每次我在MATLAB中运行代码时,如何在下一页的excel工作表中更新计算的数据? [英] How can I update calculated data in my excel sheet in the next column each time I run my code in MATLAB?

查看:154
本文介绍了每次我在MATLAB中运行代码时,如何在下一页的excel工作表中更新计算的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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,以创建值的数据集.我能够将数据写入文件,但是现在我需要第二次运行代码时,它将计算出的数据写入到下一列,同时保持旧数据的安全.我的代码要么覆盖同一列中的数据,要么每次都要手动输入特定行列交点的位置.

I have to update my file measure.csv every time I make a change in my code in order to create a data-set of values. I am able to write data onto the file, but now i need that when my code runs for the second time, it writes the computed data onto the next column while keeping the old data safe. My code is either overwriting the data in the same column or i have to manually input the specific row column intersection location everytime.

我的代码每次运行时都会计算14个值.请告诉我一种方法,以便我可以在父函数中使用它来提高整个过程的效率.

My code computes 14 values every time it runs. Please tell me a way so that i can use it in my parent function to make the whole process more efficient.

推荐答案

首先,如果您正在编写Excel表,则我建议您使用函数xlswrite(filename,Data,sheet,pos),该函数允许您专门设置一个值,向量或矩阵到您想要的工作表中的特定位置.

Well first of all, if you are writing an Excel-Table I would rather recommend you using the function xlswrite(filename,Data,sheet,pos), which permits you to specifically set a value, vector or matrix into a specific position in a sheet you want.

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

Second: If you can use a counter that follows up the amount of rows you have written, you can do it like this:

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

我希望这会有所帮助.

这篇关于每次我在MATLAB中运行代码时,如何在下一页的excel工作表中更新计算的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆