Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

print n*m matrix in matlab

Tags:

matlab

In MATLAB I'm printing a very large matrix this way:

fid = fopen('c:\\OUTPUT.txt','wt');
fprintf(fid,'%f\t',T');
fclose(fid);

But this is not right! I want to print it like this:(\t between them and \n at the end of row)

1   2   3
4   5   6
7   8   9
10  11  12

I searched and found If it was 3*3 this was fine:

fprintf(fid,'%f %f %f\n',T');

But I in my case size change...

like image 476
bunNyBug Avatar asked Feb 22 '13 20:02

bunNyBug


People also ask

How do you display a specific element of a matrix in MATLAB?

The most common way is to explicitly specify the indices of the elements. For example, to access a single element of a matrix, specify the row number followed by the column number of the element. e is the element in the 3,2 position (third row, second column) of A .


1 Answers

You may also want to look at dlmwrite

You can set delimiters, precision, etc.

dlmwrite('myfile.txt', M, 'delimiter', '\t', 'precision', 6)

Where M is your matrix.

like image 61
AGS Avatar answered Oct 14 '22 10:10

AGS