using less than operator and combination of if and for statement

10 ビュー (過去 30 日間)
Walaa
Walaa 2022 年 12 月 3 日
回答済み: Walter Roberson 2022 年 12 月 3 日
I'm trying to use the less than operator and getting the following error (for vertical Height 102 Error: Invalid operator use). also Is the for and if statement combination I'm using correct?
%calculate Rim to disc ratio
shortestRimLength=minDistance;
DiameterOfDisc=verticalHeight
%Rim to disk ratio estimation
RDR=shortestRimLength./DiameterOfDisc;
for DiameterOfDisc<102
if RDR>0.4
disp('NORMAL')
msgbox('NORMAL')
elseif RDR <0.2 && RDR>=0.4
disp('EARLY GLAUCOMA ')
msgbox('EARLY GLAUCOMA ')
else RDR<=0.2;
disp(' ADVANCED GLAUCOMA ')
msgbox(' ADVANCED GLAUCOMA ')
end

採用された回答

Walter Roberson
Walter Roberson 2022 年 12 月 3 日
You cannot use a condition in for : if you need to use a condition you should be using while
Note that when you use while, at least one of the variables involved in the test needs to be changing inside the loop, or else you will end up with an infinite loop (unless you do have something changing and you use break)
Your RDR is not changing inside the loop, so if you entered the loop at all, you would never exit the loop.
I have to wonder if what you want is instead
if DiameterOfDisc < 102
rather than a loop at that point.

その他の回答 (1 件)

Fifteen12
Fifteen12 2022 年 12 月 3 日
Your for loop is using a conditional as its input. In MATLAB you need to specify a list.
Try:
for DiameterOfDisc = 1:102

カテゴリ

Help Center および File ExchangeExplore and Edit Images with Image Viewer App についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by