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

前端 未结 3 1016
轮回少年
轮回少年 2020-12-28 08:51

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
         


        
3条回答
  •  佛祖请我去吃肉
    2020-12-28 09:32

    Building on snakile's earlier answer: to write myMatrix to myFile.txt, using CR/LF as line terminator ('pc'), otherwise, you should use LF ('unix'):

    dlmwrite('myFile.txt', myMatrix,'newline','pc');
    

    To read the file into a new matrix:

    newMatrix = dlmread('myFile.txt');
    

提交回复
热议问题