matlab————矩阵输出到txt

时间:2024-02-18 10:19:36
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);