How do i implement a while loop in my if loop

I am trying to create a while loop which only occurs if the value of one of my variables is zero, but my loop isnt working. how do i impliment this condition correctly?
if v == 0
a = 0;
elseif v~= 0
aStr = input ('What is your value for angle of projection?: ' , 's'); %angle of projection
a = str2double(aStr);
while ~isnumeric(a) || isnan(a) || ~isreal(a) || a > 90 || a == 0 && h == 0 ||
if isnan(a)
disp('This is not a number.')
elseif ~isreal(a)
disp('This is not a Real number')
elseif a > 90
disp('your angle of projection cannot be higher than a right angle')
elseif a == 0 && h == 0
disp('Your angle of projection must be greater than zero if your height is zero')
end
aStr = input ('What is your value for angle of projection?: ' , 's');
a = str2double(aStr);
end

3 件のコメント

Bjorn Gustavsson
Bjorn Gustavsson 2022 年 11 月 22 日
In your matlab editor set a debug-stop at the first line (click on the tick just right of the line-number). Then run the script. Now you will enter into debug-mode, which allows you to inspect every variable in whatever way you want, plot, display or whatever. When doing so you'll figure out which conditions are messing up your script.
Benjamin
Benjamin 2022 年 11 月 22 日
@Bjorn Gustavsson i found the mistake, i added an unnecesary or function which kept bugging out my code
Jan
Jan 2022 年 11 月 22 日
There are no "if loops" in any programming language I know.

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeEnvironment and Settings についてさらに検索

製品

リリース

R2022b

質問済み:

2022 年 11 月 22 日

コメント済み:

Jan
2022 年 11 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by