views:

39

answers:

3

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?

A: 

That should work. Is myMatrix definitely a matrix?

>> class(myMatrix)
ans =
double

E.g. cell arrays can't be saved as ascii files i think

second
A: 

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

>> myMatrix2 = double(myMatrix);
>> save myFile.txt myMatrix2 -ASCII
Ghaul
+1  A: 

To write myMatrix to myFile.txt:

dlmwrite('myFile.txt', myMatrix);

To read the file into a new matrix:

newMatrix = dlmread('myFile.txt');
snakile