How to compare values in two vectors and modify a new vector based on that results?
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
James Tursa
2018 年 1 月 20 日
編集済み: James Tursa
2018 年 1 月 20 日
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 件のコメント
その他の回答 (1 件)
Star Strider
2018 年 1 月 20 日
編集済み: Star Strider
2018 年 1 月 20 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Discrete Multiresolution Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!