execute function if any evaluation is found to be false
1 回表示 (過去 30 日間)
古いコメントを表示
I have a bunch of variables, and my program checks to make sure they are equal:
if strcmp(TrueValMat{2,1}, BOX(1,:))...
&& strcmp(TrueValMat{2,2}, BOX(2,:))...
&& strcmp(TrueValMat{2,3}, BOX(3,:))...
&& strcmp(TrueValMat{2,4}, BOX(4,:))...
&& strcmp(TrueValMat{2,5}, BOX(5,:))...
&& strcmp(TrueValMat{2,6}, BOX(6,:))...
&& strcmp(TrueValMat{2,7}, BOX(7,:))...
&& strcmp(TrueValMat{2,8}, BOX(8,:))
set(handles.certifyButton, 'enable', 'on');
end
I know it is ugly, but it works. It indexes cells from an excel file (TrueValMat), and compares each cell to a value in an array (BOX). if they all match, a button is enabled in a GUI.
I want it to do the opposite. I want this to compare the cells from TrueValMat and BOX, and if any of them are found to be unequal, then the condition will be met, and the GUI button will be enabled. I don't care if only a single pair doesn't match, or all of them don't match. as soon as there is a logical 0 found, it trips the condition.
How would I do this?
0 件のコメント
回答 (2 件)
Walter Roberson
2020 年 11 月 16 日
if ~( strcmp(TrueValMat{2,1}, BOX(1,:))...
&& strcmp(TrueValMat{2,2}, BOX(2,:))...
&& strcmp(TrueValMat{2,3}, BOX(3,:))...
&& strcmp(TrueValMat{2,4}, BOX(4,:))...
&& strcmp(TrueValMat{2,5}, BOX(5,:))...
&& strcmp(TrueValMat{2,6}, BOX(6,:))...
&& strcmp(TrueValMat{2,7}, BOX(7,:))...
&& strcmp(TrueValMat{2,8}, BOX(8,:)) )
set(handles.certifyButton, 'enable', 'on');
end
3 件のコメント
Walter Roberson
2020 年 11 月 16 日
If even one of the conditions is false then the && part would be false, and ~ of that would be true.
The only way for the chain to be false would be if all of the components of the && are true (that is, everything matches), and then not of that would be false.
De Morgan's Laws:
~(A|B) = (~A)&(~B)
~(A&B) = (~A)|(~B)
Sulaymon Eshkabilov
2020 年 11 月 16 日
if strcmp(TrueValMat{2,1}, BOX(1,:))==false...
&& strcmp(TrueValMat{2,2}, BOX(2,:))==false...
&& strcmp(TrueValMat{2,3}, BOX(3,:))==false...
&& strcmp(TrueValMat{2,4}, BOX(4,:))==false...
&& strcmp(TrueValMat{2,5}, BOX(5,:))==false...
&& strcmp(TrueValMat{2,6}, BOX(6,:))==false...
&& strcmp(TrueValMat{2,7}, BOX(7,:))==false...
&& strcmp(TrueValMat{2,8}, BOX(8,:))==false
set(handles.certifyButton, 'enable', 'on');
end
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!