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 ...).
0 个评论
回答(1 个)
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!