我有7个不同长度的向量(L_mean_argil、L_Min_argil和L_Max_argil(,我想用所有向量创建一个.sae文件。这是我的代码:
fileID = fopen('BN_for_prediciting_zeros_argilliti_v1.sae','w');
fprintf(fileID,'L_mean_argil, L_Min_argil, L_Max_argil, R_mean_argil, R_Min_argil, R_Max_argil, Zero_argiln');
fprintf(fileID,'%6.4f, %6.4f, %6.4f, %6.4f, %6.4f, %6.4f, %6.4f n', L_mean_argil, L_Min_argil, L_Max_argil, R_mean_argil, R_Min_argil, R_Max_argil, Zero_argil');
fclose(fileID);
它不能正确地写入矢量。有人能帮我吗?
我期待这个:
L_mean_argil(1) L_Min_argil(1) ... Zero_argil(1)
L_mean_argil(2) L_Min_argil(2) ... Zero_argil(2)
...
L_mean_argil(end) L_Min_argil(end) ... Zero_argil(end)
但在一些向量的最后部分,会有空单元格与其他值为的单元格相关联
这里有一个答案,假设您想在缺少数据的行中留空。
%Sample Data all of different lengths
a = 1:4;
b = (1:6)+1;
c = (1:5)+2;
%Get max length
maxSize = max([numel(a) numel(b) numel(c)]);
%Convert to Cell array if it isn't already
a = num2cell(a,1);
b = num2cell(b,1);
c = num2cell(c,1);
%Initialize a cell to hold everything. Init to the max size
output = cell(3,maxSize);
output(1,1:numel(a)) = a;
output(2,1:numel(b)) = b;
output(3,1:numel(c)) = c;
%Print...
fprintf('%0.1f,%0.1f,%0.1fn',output{:})
结果如下:
1.0,2.0,3.0
2.0,3.0,4.0
3.0,4.0,5.0
4.0,5.0,6.0
,6.0,7.0
,7.0,