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

1 回表示 (過去 30 日間)
avram alter
avram alter 2021 年 5 月 2 日
コメント済み: Image Analyst 2021 年 5 月 3 日
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?

回答 (1 件)

Image Analyst
Image Analyst 2021 年 5 月 2 日
Simply use isequal():
if isequal(TrueValMat, BOX)
handles.certifyButton.Enable = 'on'; % Using new and modern OOP way instead of old set() way.
end
  2 件のコメント
avram alter
avram alter 2021 年 5 月 3 日
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 2021 年 5 月 3 日
Please attach TrueValMat, BOX in a .mat file so people can try things.
save('answers.mat', 'TrueValMat', 'BOX');
Attach a screenshot of your "indicator".

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

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by