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

4 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Adam
Adam el 11 de Abr. de 2017
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.

Más respuestas (1)

ES
ES el 11 de Abr. de 2017
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'

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by