operand (&&) error when trying to set a parameter

2 views (last 30 days)
I have a block of code that evaluates one matrix, BOX, with anohter matrix, TruveValMat. each of these has 8 values that need to be compared, when they all come back as equal, it enables a button on a GUI:
if strcmp(TrueValMat{1,1}, BOX(1,:)...
&& strcmp(TrueValMat{1,2}, BOX(2,:))...
&& strcmp(TrueValMat{1,3}, BOX(3,:))...
&& strcmp(TrueValMat{1,4}, BOX(4,:))...
&& strcmp(TrueValMat{1,5}, BOX(5,:))...
&& strcmp(TrueValMat{1,6}, BOX(6,:))...
&& strcmp(TrueValMat{1,7}, BOX(7,:))...
&& strcmp(TrueValMat{1,8}, BOX(8,:)))
set(handles.certifyButton, 'enable', 'on');
I am now getting this error when I run I get up to this part:
Operands to the logical and (&&) and or (||) operators must be convertible to logical scalar values.
is there any way to fix this error?

Answers (1)

Image Analyst
Image Analyst on 2 May 2021
Simply use isequal():
if isequal(TrueValMat, BOX)
handles.certifyButton.Enable = 'on'; % Using new and modern OOP way instead of old set() way.
end
  2 Comments
avram alter
avram alter on 3 May 2021
I have an indicator that occurs when each position in BOX becomes equal to the position in TruveValMat. it looks like this:
if strcmp(TrueValMat{1,n}, BOX(n,:)) %cannot sub-index to CELL types normally, must use this method
set(handles.Box(n), 'BackgroundColor', 'g');
else
set(handles.Box(n), 'BackgroundColor', 'r');
end
Box is the name of panel that corresponds to each value of BOX. when all of the panels turn green, that would mean that BOX = TruevalMa at each position. however, despite each box going green, the certify button does not get enabled, whether I use the new OOP method or the old one
Image Analyst
Image Analyst on 3 May 2021
Please attach TrueValMat, BOX in a .mat file so people can try things.
save('answers.mat', 'TrueValMat', 'BOX');
Attach a screenshot of your "indicator".

Sign in to comment.

Categories

Find more on Software Development Tools in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!