Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I save a matrix of integers to a text file in Matlab?

I have a 2D matrix myMatrix of integers which I want to save its content to a text file. I did the following:

save myFile.txt myMatrix -ASCII

I get this message:

Warning: Attempt to write an unsupported data type to an ASCII file. Variable 'myMatrix' not written to file. and nothing is written.

What to do?

like image 728
snakile Avatar asked Aug 23 '10 10:08

snakile


2 Answers

To write myMatrix to myFile.txt:

dlmwrite('myFile.txt', myMatrix);

To read the file into a new matrix:

newMatrix = dlmread('myFile.txt');
like image 127
snakile Avatar answered Nov 05 '22 18:11

snakile


You have to convert your matrix to double before using save.

>> myMatrix2 = double(myMatrix);
>> save myFile.txt myMatrix2 -ASCII
like image 2
Ghaul Avatar answered Nov 05 '22 19:11

Ghaul