1.matlab里怎么把得到的矩阵存成dat格式
%初始化矩阵
result = zeros(10,10);
[nRow, nColumn] = size(result);
nSize = nRow * nColumn;
%将矩阵存入文件中
fid = fopen(filename,'rb');
if (fid==1)
error('Cannot open image file。press CTRL-C to exit ');
end
temp = fwrite(fid, result', 'uchar');
fclose(fid);
%从文件中读取数据,并存入矩阵
fid = fopen(filename,'rb');
if (fid==1)
error('Cannot open image file。press CTRL-C to exit ');
end
temp = fread(fid, nSize, 'uchar');
fclose(fid);
result = reshape(temp, [nRow nColumn])';
2.dat文件怎么在matlab转为矩阵形式
首先把源文件的第一行(属性名,文字)删掉
然后导入数据就可以。
默认就是矩阵格式。
或者
1. 在matlab输入g=[],在workspace中点开g
2. 打开excel,把dat文件拽到excel中。复制需要的数据,粘贴过去就好了。
3. 改变矩阵式样可以用B=reshape(A,m,n)其中A是原来的矩阵,m是变化后矩阵的行数,n是变化后矩阵的列数,B就是你要的结果。
3.怎么将matlab中数据保存为txt或dat格式
try this:
>> dlmwrite('a.txt',a,'delimiter',' ','newline','pc')
>> !type a.txt
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
%read Matlab help to see the usage of function dlmwrite.