MATLAB: How to compare values in two vectors and modify a new vector based on that results

comapreifmatrixvectors

Hello,
I am comparing two vector angles t1 and t2, and if the cell in the t1>=t2 then the azmiuth angle t3 = Az1 if not t3 = Az2. This is should be for every element in the vector. I tried "if-else" but always giving me the t3=Az2.
Azd1;
Azd2 ;
t1;
t2;
if t1>= t2;
Azd = Azd1
else Azd = Azd2
end
I appreciate if somebody can help.
Thank you.
Hassan

Best Answer

If Azd1 and Azd2 are vectors, then
Azd = Azd2;
x = (t1>=t2);
Azd(x) = Azd1(x);
If Azd1 and Azd2 are scalars, then
Azd = zeros(size(t1));
x = (t1>=t2);
Azd(x) = Azd1;
Azd(~x) = Azd2;