每次我在 MATLAB 中 运行 我的代码时,如何更新下一列 excel sheet 中的计算数据?

How can I update calculated data in my excel sheet in the next column each time I run my code in MATLAB?

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 个值。请告诉我一种方法,以便我可以在我的父函数中使用它来使整个过程更有效率。

首先,如果你正在写一个 Excel-Table,我宁愿推荐你使用函数 xlswrite(filename,Data,sheet,pos),它允许你专门设置一个值,向量或矩阵到你想要的 sheet 中的特定位置。

第二:如果你可以使用一个计数器来跟踪你写的行数,你可以这样做:

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

希望对您有所帮助。