How to loop and calling data from excell

2 次查看(过去 30 天)
i have 100 column vector of data in excell
i need to call the column vector to matlab for iteration and get the value from nonlinier least square
it is so tiring to copy one set of data and do iteration and then copy again the second column data until 100 set for iteration
here is the code look like :
clc clear all close all
global data r p0 w
data = [0.066755733 0.053817978 0.034412989 0.024237233 0.016791611 0.012890878 0.011604633]';
r = [0.8 0.9 1 1.1 1.2 1.3 1.4]';
w = 10;
p0 = rand(2,1);
[p,ssq,cnt] = LMFnlsq2(@resid,ones(2,1),'Display',[-1e4,0],'MaxIter',1e6);
p = p.*p0;
a = p(2)/(3*p(1))
b = p(1)-a
res = resid(p./p0); plot(r,data,'o-', r,res(1:end-1)+data,'-or')
note that the data above is one of column vector data from excell that i copy manually,,
the question is how to make the iteration automatically so after one iteration of data, get and save the value a and b, it will move to next iteration and call next data from excell
so in the end i will get 100 colum vector of a and b

回答(1 个)

Iain
Iain 2013-6-6
Roughly you want something like this:
[n t r] = xlsread(filename);
for i = 1:number_of_columns
col = [r{startrow:endrow,i}];
do stuff
a(i) = p(2)/(3*p(1));
b(i) = p(1)-a;
end
  2 个评论
Surpan
Surpan 2013-6-6
actually like that... i need to read data from excell first and then do the iteration
but ive got confused with your code
sorry i just new to matlab so i asked you
where the part that data will change for next iteration? i mean can you help me with the actual code?
Surpan
Surpan 2013-6-6
编辑:Surpan 2013-6-6
uh nvm, :D
i already figure it out thanks anyway

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by