フィルターのクリア

Problem in while loop when input is characters or words

2 ビュー (過去 30 日間)
Jian Gui
Jian Gui 2014 年 6 月 23 日
コメント済み: David Sanchez 2014 年 6 月 24 日
Hi all. I am trying to make a while loops that will keep on running if the user input is a str, a number less and equal 0 or the number is longer the length of my vector. But it doesn't work, plz help:)
deleterowStr=input('Please enter the number of the row:','s');
deleterow=str2num(deleterowStr);
while ~((~isempty( choiceNum) && deleterow <=0 || deleterow > length(W)) || strcmpi(deleterowStr,'')==1)
disp('Invaild row number')
deleterowstr=input('Please enter the number of the row:','s');
deleterow=str2num(deleterowstr);
end
thx:)

回答 (1 件)

David Sanchez
David Sanchez 2014 年 6 月 23 日
You do not say who is either W or choiceNum, but with the two variables in play, you can do it like this.
Watch the capital S in deleterowStr within the while loop
deleterowStr = input('Please enter the number of the row:','s');
deleterow = str2double(deleterowStr);
while ~strcmpi(deleterowStr,'') || deleterow <= 0
disp('Invaild row number')
deleterowStr = input('Please enter the number of the row:','s');
deleterow = str2double(deleterowStr);
end
  5 件のコメント
Jian Gui
Jian Gui 2014 年 6 月 23 日
actually it works now, but i can't exit the while loops:S
David Sanchez
David Sanchez 2014 年 6 月 24 日
To exit the loop ( while-loop I gave you ) do not type anything and push Enter

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

カテゴリ

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