How to compare values in two vectors and modify a new vector based on that results?
2 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
James Tursa
on 20 Jan 2018
Edited: James Tursa
on 20 Jan 2018
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;
0 Comments
More Answers (1)
Star Strider
on 20 Jan 2018
Edited: Star Strider
on 20 Jan 2018
Try this anonymous function:
va = @(t1,t2,Az1,Az2) (t1 >= t2).*Az1 + (t1 < t2).*Az2;
Az1 = 10;
Az2 = 20;
Result1 = va(1,2,Az1,Az2)
Result2 = va(2,1,Az1,Az2)
Result1 =
20
Result2 =
10
0 Comments
See Also
Categories
Find more on EEG/MEG/ECoG in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!