数据存取格式
filename1 = 'g.txt';
fid1 = fopen(filename1,'w');
for i = 1 : length(g)
for j=1:size(g,2)
if(j==1)
fprintf(fid1,'{%.16f,',g(i,j));
elseif(j>1&&j<151)
fprintf(fid1,'%.16f,',g(i,j));
else
fprintf(fid1,'%.16f},\n',g(i,j));
end
end
%fprintf(fid1,'\n');
end
fclose(fid1);
得到:
添加换行、中括号
进阶版本
自动删掉末尾行末尾位置逗号
%%
filename1 = 'true_trace0507.txt';
fid1 = fopen(filename1,'w');
for i = 1 : size(true_trace,2)
if(i<21)
for j=1:length(true_trace)
if(j==1)
fprintf(fid1,'%.16f,',true_trace(j,i));
elseif(j>1&&j<60)
fprintf(fid1,'%.16f,',true_trace(j,i));
else
fprintf(fid1,'%.16f,\n',true_trace(j,i));
end
end
else
for j=1:length(true_trace)
if(j==1)
fprintf(fid1,'%.16f,',true_trace(j,i));
elseif(j>1&&j<60)
fprintf(fid1,'%.16f,',true_trace(j,i));
else
fprintf(fid1,'%.16f',true_trace(j,i));
end
end
end
%fprintf(fid1,'\n');
end
fclose(fid1);
天工C语言3×3赋值
#include <stdio.h>
int main() {
int array[3][3] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
// 打印数组内容以验证赋值
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
printf("%d ", array[i][j]);
}
printf("\n");
}
return 0;
}