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!