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!