1

In Matlab 2010a, I create a new file data.txt and write a matrix into the file using the following codes. And this works.

a=[1,2,3;3,4,5]; fid=fopen('C:\Users\TOSHIBA\Desktop\data.txt','wt'); fprintf(fid,'%g\n',a); fclose(fid);

However, when I use the same commands in matlab engine as the following statements (written in C language), I can't create a new file data.txt or write a matrix into the file.

engEvalString(eg,"a=[1,2,3;3,4,5];");
engEvalString(eg,"fid=fopen('C:\Users\TOSHIBA\Desktop\data.txt','wt');");
engEvalString(eg,"fprintf(fid,'%g\n',a);");
engEvalString(eg,"fclose(fid);");

How can I fix this?

Jeff
  • 12,555
  • 5
  • 33
  • 60
chen zhong
  • 11
  • 2

1 Answers1

0

Try this

csvwrite('C:\Users\TOSHIBA\Desktop\data.txt',a);
aarbelle
  • 1,023
  • 8
  • 17