如何在Matlab中保存多维数组? [英] How to save multi-dimensional array in matlab?
问题描述
我有一个数组M=(1000000,12,2,2)
.
如何将其写入文件以供日后使用?
How do I write it to a file to work on later?
save('filename.txt','M','-ASCII')
似乎不起作用...
此致
推荐答案
1)就像@Shai的回答一样,您可以将其保存为mat文件
1) just like the answer from @Shai, you can save it to be mat file
2)如果要将其保存为txt文件,则可以通过以下方式进行操作:
2) if you want to save it to be txt file, you can do it in this way:
clear;clc;
M=[1000000,12,2,2];
dlmwrite('a.txt',M); % save M to file--a.txt
type a.txt; % print content in a.txt
M = dlmread('a.txt'); % load content of a.txt to M and then you will have 'M=[1000000,12,2,2]'
3)您还可以使用fopen,fprintf,fclose将矩阵保存到文件中.检查这篇文章:如何在MATLAB中的.txt文件中保存数据
3) you can also use fopen, fprintf, fclose to save a matrix to a file. check this post: How to save data in .txt file in MATLAB
4)对于您拥有的代码,我对其进行了测试.有用.我拥有的Matlab版本是R2011b.请再次检查您的代码.我用来测试的代码如下:
4) for the code you have, I tested it. It works. The Matlab version I have is R2011b. please check your code again. The code I used to test is as follows:
clear;clc;
M=[1000000,12,2,2];
save('b.txt','M','-ASCII');
clear;clc;
M = load('b.txt','-ASCII');
这篇关于如何在Matlab中保存多维数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!