天天看點

matlab————矩陣輸出到txt

matlab如何輸出矩陣到txt并指定數的精度 (2013-11-20 16:50:43)轉載▼

标簽: matlab 輸出資料

假設你的資料矩陣為a;

[m n] = size(a);

[filename pathname] = uiputfile{\'*.txt\',\'Select Save file\');

if ~filename

return;

else

str = [pathname filename];

fin = fopen(str,\'wt\');

for i = 1:m

for j =1:n

fprintf(fin,\'.3f\t\',a(i,j)); %指定輸出格式和小數點後有效位數

end

fprintf(fin,\'\n\');

end

fclose(fin);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

MATLAB初學者必讀

clear,clc

a = rand(12000,1004);

fid = fopen(\'2.txt\',\'w\');

fprintf(fid,[\'%f %f %f %f \' repmat(\'%f\',1,1000) \'\r\n\'],a\');

fclose(fid);