フィルターのクリア

please guide me how to do if loop

1 回表示 (過去 30 日間)
Saleh
Saleh 2022 年 10 月 18 日
コメント済み: Walter Roberson 2022 年 10 月 18 日
hello i want to write in Matlab script that asks the user to enter a number between 1 to 3 If the user enters 1 it will show this graph below
inpt = "choose from 1 to 3 : ";
s = input(inpt);
k = 6 + 6;
size = 30 + 9;
t = linspace(-pi,pi,1000);
X = size * cos (k*t) .* cos(t);
Y = size * cos (k*t) .* sin(t);
plot(X,Y,'b*')
title('Matlab Flower')
If the user enters 2 it will show a table (( still i didn't complete it ))
If the user enters 3 it will show the Sinusoidal Graph
figure (1)
t=linspace(-pi/2,pi/2,1000);
X = 6*cos(2*pi*20*t) + 2*sin(2*pi*10*t);
plot(t,X, ‘r’)
title('Sinusoidal Graph')
and if the user inputs any other number ((more tnan 3 or below 1 )), they notice "You have picked invalid option" is displayed
please help me

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 10 月 18 日
while true
s = input(inpt);
check whether s is numeric scalar 1 2 or 3
if it is a valid choice
break;
end
give warning message
end
process the choice
  3 件のコメント
Saleh
Saleh 2022 年 10 月 18 日
what about , if the user inputs any other number ((more tnan 3 or below 1 )), they notice "You have picked invalid option" is displayed
please help me
Walter Roberson
Walter Roberson 2022 年 10 月 18 日
You put that code in where I wrote the outline "give warning message"
Most of what I wrote is outline. The literal parts are "while true" and "break"

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by