comparison of two column vectors

sir/madam i have two column vectors, i want to compare element by element and want to know which is large or small.
please help me, how can i write command for it.

Réponses (1)

per isakson
per isakson le 9 Avr 2022
Modifié(e) : per isakson le 9 Avr 2022
An example
%%
v1 = rand( 6,1 );
v2 = rand( 6,1 );
%%
v1 > v2
ans = 6×1 logical array
1 0 0 1 1 1
This result tells us that the first, fourth, fifth and sixth element of v1 are larger than the corresponding elements of v2

8 commentaires

Image Analyst
Image Analyst le 9 Avr 2022
@pramod kumar it would benefit you to invest two hours here:
after that you'll be able to answer questions like this, and many more, yourself.
Chaudhary P Patel
Chaudhary P Patel le 15 Avr 2022
@per isakson sir, if i am comparing the v1 and v2, for the element logical array is showing 1, i have to write V vector. For thi case how can i proceed the loops.
if v1<=v2 % If linear
V= K*u;
else % If nonlinear
V=K*u;
end
per isakson
per isakson le 15 Avr 2022
I don't understand your comment.
Read if, elseif, else, Execute statements if condition is true and please notice: An expression is true when its result is nonempty and contains only nonzero elements (logical or real numeric).
Chaudhary P Patel
Chaudhary P Patel le 16 Avr 2022
Modifié(e) : per isakson le 17 Avr 2022
I want to write coding for the element of LV having zero or One .
how can wrote for that specific element.
Example,
for n=1:1:5
for LV=v1<=v2 % v1 v2 are column vectors
if LV==1
Fs= xyz; % for that element of LV which have one
else
Fs=abc; % for that element of LV which have zero
end
end
end
It will work sir?
Chaudhary P Patel
Chaudhary P Patel le 18 Avr 2022
@per isakson sir, please suggest me.
per isakson
per isakson le 18 Avr 2022
No it will not work. Why don't just try to run it?
Did you spend a couple of hours with MATLAB Academy - Free 2 hour training ?
Why do you have two for-loops. One should be enough.
In a statement like, for LV=v1<=v2, the expression, v1<=v2, must evaluate to a row. See help on for-else-end.
In the assignment, Fs=abc;, Fs is overwritten each time LV is false.
Chaudhary P Patel
Chaudhary P Patel le 19 Avr 2022
@per isakson @Michael Kleder @Matt J Sir the real problem is, I have 2 type of Column vector of 6X1
F_s1=(1;5;7;4;6;8)
F_s2=(0;5;8;3;7;7)
and
F_r1=(0;1;5;7;4;3)
F_r2=(1;2;11;1;5;9)
sir i have to compare F_s <= F_r each elemet one by one and which satisfy the condition for that some other actions i have to take. So suggest me how can i do it element by element not a complete one.
Chaudhary P Patel
Chaudhary P Patel le 19 Avr 2022
please @per isakson sir, suggest me how can i compare element by element?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Graphics Performance dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by