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

2 visualizaciones (últimos 30 días)
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

Respuesta aceptada

James Tursa
James Tursa el 20 de En. de 2018
Editada: James Tursa el 20 de En. de 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;

Más respuestas (1)

Star Strider
Star Strider el 20 de En. de 2018
Editada: Star Strider el 20 de En. de 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

Categorías

Más información sobre EEG/MEG/ECoG en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by