function []= process(f1, f2, f3, f4, height, th)
%%omitted the the large code from in between in order to just propose the problem%%
ValuesInInches(12)=t1*t;
ValuesInInches(8)=realneck(f1,f2,height,th);
ValuesInInches(14)=t3*t;
ValuesInInches(7)=t4*t;
ValuesInInches(11)= ValuesInInches(7);
ValuesInInches(5)=t5*t;
ValuesInInches(4)=t6*t;
ValuesInInches(6)=t7*t;
ValuesInInches(10)=t8*t;
ValuesInInches(9)=t9*t;
ValuesInInches(3)=t9*t1;
ValuesInInches(1)=t*t10;
ValuesInInches(2)=t11*t;
ValuesInInches(13)= measureknee(a5,t);
ValuesInInches=ValuesInInches';
file='measure.csv';
measurements{1,1}='Shirt Length';
measurements{2,1}='Full Shoulders';
measurements{3,1}='Sleeves';
measurements{4,1}='Muscle';
measurements{5,1}='Chest';
measurements{6,1}='Stomach';
measurements{7,1}='Hip';
measurements{8,1}='Neck';
measurements{9,1}='Trouser length';
measurements{10,1}='Trouser waist';
measurements{11,1}='Trouser hip';
measurements{12,1}='Thigh';
measurements{13,1}='Knee';
measurements{14,1}='Inseam';
T= table(measurements,ValuesInInches);
writetable(T,file);
end
每次创建代码更改时,我都必须更新我的文件measure.csv,以创建值的数据集。我能够将数据写入文件,但是现在我需要第二次运行代码时,它将计算出的数据写入下一列,同时保持旧数据的安全。我的代码要么覆盖同一列中的数据,要么每次都必须手动输入特定的行列交点位置。
我的代码每次运行时都会计算14个值。请告诉我一种方法,以便我可以在父函数中使用它以使整个过程更高效。
答案 0 :(得分:1)
首先,如果要编写Excel表,我建议您使用函数xlswrite(filename,Data,sheet,pos)
,该函数可以将值,向量或矩阵专门设置为工作表中的特定位置想要。
第二:如果您可以使用一个计数器来跟踪您已写入的行数,则可以这样做:
function []= process(f1, f2, f3, f4, height, th, counter)
% Your code...
% suppose you want to write ValuesInInches into the next row
strCounter = ('A':'Z'); % = 'ABC...Z'
strPos = [strCounter(counter) '1']; % = 'B1' for instance
xlswrite(file,ValuesInInches,strPos);
end
我希望这会有所帮助。