How to make a loop to do a specific operation for multiple variables?

1 次查看(过去 30 天)
lambda = num(:,1);
RefInd1 = num(:,2);
RefInd2 = num(:,3);
RefInd3 = num(:,4);
% For the draw ratio DR=1.00
ny1 = interp1(lambda,RefInd1, 590);
nb1 = interp1(lambda,RefInd1, 485);
nr1= interp1(lambda,RefInd1, lambda(end));
abbenumber1 = ((ny1-1)/(nb1-nr1))
% For the draw ratio DR=1.05
ny2 = interp1(lambda,RefInd2, 590);
nb2 = interp1(lambda,RefInd2, 485);
nr2 = interp1(lambda,RefInd2, lambda(end));
abbenumber2 = ((ny2-1)/(nb2-nr2))
% For the draw ratio DR=1.10
ny3 = interp1(lambda,RefInd3, 590);
nb3 = interp1(lambda,RefInd3, 485);
nr3= interp1(lambda,RefInd3, lambda(end));
abbenumber3 = ((ny3-1)/(nb3-nr3))
I want to make a loop to apply this equation (abbenumber) for the different variables of (RefInd1, RefInd2 ...).

回答(1 个)

KALYAN ACHARJYA
KALYAN ACHARJYA 2020-1-12
编辑:KALYAN ACHARJYA 2020-1-12
Assuming those results are array, hence used cell array { }. If numeric, please change to array [ ]
RefInd={};
ny=cell(1,3);;nb=cell(1,3);;nr=cell(1,3); abbenumber=zeros(1,3);
lambda = num(:,1);
for k=2:4
RefInd{k} = num(:,k);
end
for i=1:3
% For the draw ratio DR=1.00
ny{i}= interp1(lambda,RefInd{i}, 590);
nb{i}= interp1(lambda,RefInd{i}, 485);
nr{i}= interp1(lambda,RefInd{i}, lambda(end));
abbenumber(i) = ((ny{i}-1)/(nb{i}-nr{i}))
end
  1 个评论
Muhamed Sewidan
Muhamed Sewidan 2020-1-13
it gives me this error !
Error using griddedInterpolant
The grid vectors do not define a grid of points that match the given
values.
Error in interp1 (line 161)
F = griddedInterpolant(X,V,method);

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by