Assuming 9 needs to be just to the right of 999 (and not handling the last column at all), I would probably do this as follows:
conditionFail = Z(:,1:end-1)==999 & not(Z(:,2:end)==9)
if any(conditionFail(:))
disp('error)
return
end
It is possible to put all the code into if statement (without needing to pre-specify the condition), like this ...
if any(any(Z(:,1:end-1)==999 & not(Z(:,2:end)==9)))
disp('error)
return
end
but I think that is more obfuscated.
1 Comment
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/335045-basic-comparison-between-columns#comment_445281
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/335045-basic-comparison-between-columns#comment_445281
Sign in to comment.