Operands to the || and && operators must be convertible to logical scalar values.
1 回表示 (過去 30 日間)
古いコメントを表示
Elzbieta Trynkiewicz
2018 年 12 月 23 日
回答済み: Image Analyst
2018 年 12 月 24 日
I have such kind of simple code. But when I tried to include it in "if else" like below, this command: Operands to the || and && operators must be convertible to logical scalar values, just appears.
prompt1 = {'sth 1:' , 'sth 2:' };
title = 'Front Range';
dims = [1 50] ;
definput = {' ', ' '};
x1 = inputdlg(prompt1,title,dims,definput);
if ge(x1, 100) || lt(x1, 1)
return
else
prompt2 = {'sth 3:' , 'sth 4:' };
title2 = 'Post-Range';
dims2 = [1 50];
definput2 = {' ',''};
x2 = inputdlg(prompt1,title2,dims2,definput2);
end
1 件のコメント
Rik
2018 年 12 月 23 日
With the debugger enabled, you can try to evaluate the parts of that statement. Both parts should be a logical scalar. Apparently that is currently not the case.
採用された回答
Walter Roberson
2018 年 12 月 23 日
inputdlg() returns a cell array of character vectors. You need to use str2double(x1) to convert to numeric form. Watch out for nan, which will be returned for empty values or for values that are not valid single numbers.
0 件のコメント
その他の回答 (1 件)
Image Analyst
2018 年 12 月 24 日
Try this:
ca = inputdlg(prompt1, 'Front Range', dims, definput);
% ca is a cell array.
sth1 = str2double(ca{1})
sth2 = str2double(ca{2})
if sth1 < 1 || sth1 > 100 || sth2 < 1 || sth2 > 100
return;
else........
Don't use title as the name of your variable because that is the name of a built-in function.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Random Number Generation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!