Selecting specific values in a for loop, when a certain condition hold true

Hello, i've written the following script in MATLAB:
Rcon=(Rmax^2) -(Rmin^2);
Ccon= cosd(Thetamin) - cosd(Thetamax);
Scon=sin(Thetamax)-sin(Thetamin);
vN = linspace(0, 180, N);
vP = linspace(Thetamin, Thetamax, P);
for iN = 1:length(vN)
Phi = vN(iN);
G(iN)=Phi + BOC;
C2(iN)=Rcon / ((Ccon * cosd(G(iN))) + (Scon * sind(G(iN))));
C1(iN)=Rmax^2 + (C2(iN) * cosd(G(iN) + Thetamax));
A(iN)= (sqrt(C1(iN)+C2(iN)) + sqrt(C1(iN)-C2(iN)))./2;
B(iN)=C2(iN) / (2*A(iN));
for iP = 1:length(vP)
Theta = vP(iP);
R(iP)= sqrt(abs(C1(iN) - (C2(iN) * cosd(G(iN) + Theta))));
F(iN,iP)= abs(((R(iP)*(M*g*L)) *cosd(Theta)) / ...
((A(iN)*B(iN)) * sind(G(iN)+Theta)));
Ffinal =max(F);
FFfinal=min(Ffinal);
end
end
this script is designed to extract certain values for F as the values for phi and Theta change, where Phi runs from 0 to 180 for a certain number of inputted values (N), and theta lies within P input values, Thetamin and Thetamax. The variable R is also subject to changes in Phi and theta: however, in reality, we know that R falls within a certain range of values (between a maximum, Rmax, and a minimum, Rmin). I have found that with some values of Phi and Theta, the calculated values for R (line 20, including spaces) fall outside of this known range. I'd like to run the script so that I will only calculate F if the calculated value for R falls within the known range. I have attempted to use this command at line 21, but without success:
if Rmin<R(iP) && R(iP)<Rmax
Does anybody have any advice?
Cheers,
-Nathan

댓글 수: 1

Maybe an obvious question: What are the values of Rmin and Rmax? Is Rmin actually smaller then Rmax?
Also, how do you know it is without success? What is the result of your change?

댓글을 달려면 로그인하십시오.

 채택된 답변

for iP = 1:length(vP)
Theta = vP(iP);
R(iP)= sqrt(abs(C1(iN) - (C2(iN) * cosd(G(iN) + Theta))));
if R(iP) >= Rmin && R(iP) <= Rmax
F(iN,iP)= abs(((R(iP)*(M*g*L)) *cosd(Theta)) / ...
((A(iN)*B(iN)) * sind(G(iN)+Theta)));
else
F(iN,iP) = nan;
end
Ffinal =max(F);
FFfinal=min(Ffinal);
end

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Performance and Memory에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by