Operands to the || and && operators must be convertible to logical scalar values?
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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.
0 个评论
更多回答(1 个)
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'
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!