About vector comparasion question.

Hi, I know I have asked the similar question, I want to write a if statement that compare vectors, like a, b is 3 dimensional vector, however if a<=b returns a 3-dim vector that do the comparison for each entry.
Is there a command just do a whole comparison at once? Thanks.

 Réponse acceptée

Mahdi
Mahdi le 2 Avr 2013

0 votes

Have you tried using the 'or' operator?
if size(a,2)==3 | size(b,2)==3
...
elseif size(a,1)<=size(b,1)
...
end
Sorry, you weren't very clear, but I hope some of the above will help.

5 commentaires

C Zeng
C Zeng le 2 Avr 2013
Yes, but dimensional of a and b can be many, so compare them one by one is not convenient. I am wondering does MATLAB have a function to do so?
Thanks.
Yes, you want to use either all() or any():
if all(a<=b), %true if every a(i) <= b(i)
....
end
if any(a<=b), %true if at least one a(i) <= b(i)
...
end
C Zeng
C Zeng le 2 Avr 2013
Oh, yes, thanks, that function is very helpful!
Jan
Jan le 2 Avr 2013
@C Zeng: Flagging is used to tell the admins and editors, that a message violates the using conditions of the forum. Please press the "Accept" button instead of setting a flag. Thanks.
C Zeng
C Zeng le 2 Avr 2013
Sorry about that Jan! Thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by