Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How can i make a decicion in order to make my program run after it

1 回表示 (過去 30 日間)
Da'Moon
Da'Moon 2017 年 12 月 9 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
v=input('Would you like to run your programm?');
if v==yes
end
% my loop that should run after the user put yes or no for example.
For i=1:10:80
o=o*2;
if i<0 || i>0
Z(i)=1;
else
Z(i)=0;
end
end
  1 件のコメント
Greg
Greg 2017 年 12 月 9 日
Why? If I didn't want to run it, I wouldn't have called the function...
Either put the code inside the if/end block, or check the negative and put a return in the if.

回答 (1 件)

Duncan Lilley
Duncan Lilley 2017 年 12 月 11 日
It sounds like you want to place your code within an if...end expression. Refer to the documentation page, here.
For checking equality of character arrays, consider using the "strcmp" function. The documentation for this function can be found here.
Another note is that, when using "input", you may want to use the 's' parameter to indicate that you are expecting text input from the user. For more information about this parameter, take a look at the documentation page, here.
Consider the following example:
userInput = input('Enter the word "success": ', 's');
if strcmp(userInput, 'success')
disp('Correct')
else
disp('Incorrect')
end

Community Treasure Hunt

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

Start Hunting!

Translated by