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

조회 수: 1 (최근 30일)
Muhamed Sewidan
Muhamed Sewidan 2020년 1월 12일
댓글: Muhamed Sewidan 2020년 1월 13일
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