フィルターのクリア

Operands to the || and && operators must be convertible to logical scalar values?

6 ビュー (過去 30 日間)
pavan sunder
pavan sunder 2017 年 4 月 11 日
回答済み: Adam 2017 年 4 月 11 日
I am developing an app using Matlab app designer. I am pretty new to Matlab app designing so i request you to please help me. The app is a questionnaire where I have two questions and the user has to select the answers for each question. Each question is a button group and the answers are radio buttons which the user has select one of them for each question. Based on the answers selected for each question, final result is displayed.
for example
if (buttongroup1,radiobutton1) and (buttongroup2,radiobutton1) is selected
message='a'
else if (buttongroup1,radiobutton1) and (buttongroup2,radiobutton2) is selected
message='b'
else
message='c'
the approach i adopted is store the result of each selection (as number) in different variables and use them in if statements. When i run the code i am getting the following error "Operands to the and && operators must be convertible to logical scalar values"
please suggest an appropriate solution for this issue.
below is the part of the code i wrote for your reference.
properties (Access = private) hum % Description gen % Description end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
if all(app.hum=='1' && app.gen=='1')
app.results.Value='a';
elseif (app.hum=='1' && app.gen=='2')
app.results.Value='b';
else
app.results.Value='c';
end
end
% Selection changed function: HumanButtonGroup
function HumanButtonGroupSelectionChanged(app, event)
switch app.HumanButtonGroup.SelectedObject.Text
case 'yes'
sel_human=1;
case 'no'
sel_human=2;
end
app.hum=sel_human;
end
% Selection changed function: GenderButtonGroup
function GenderButtonGroupSelectionChanged(app, event)
switch app.GenderButtonGroup.SelectedObject.Text
case 'male'
sel_gender=1;
case 'female'
sel_gender=2;
end
app.gen=sel_gender;
end
end

採用された回答

Adam
Adam 2017 年 4 月 11 日
You need to use & to compare arrays of logicals.
The fact you are wrapping the comparison in an 'all' test clearly suggests you are expecting the result to be non-scalar.

その他の回答 (1 件)

ES
ES 2017 年 4 月 11 日
You are setting app.hum and app.gen to double values (1, 2 etc) . But why are you comparing them to strings ? i.e., '1', '2'
  1 件のコメント
pavan sunder
pavan sunder 2017 年 4 月 11 日
sorry typo error...if i compare with number still the same error

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

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by