execute function if any evaluation is found to be false
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Walter Roberson
am 16 Nov. 2020
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 Kommentare
Walter Roberson
am 16 Nov. 2020
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
am 16 Nov. 2020
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
Siehe auch
Kategorien
Mehr zu Code Execution finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!