if statement inside for loop location issues

1 回表示 (過去 30 日間)
DARLINGTON ETAJE
DARLINGTON ETAJE 2019 年 8 月 14 日
コメント済み: DARLINGTON ETAJE 2019 年 8 月 16 日
Imagine this
A=[B C D E];
B=[1;2;3;1;9,0,4,5];
C=[1;2;3;2;3;2;1;2];
D=[8;3;5;6;1;2;7;4];
E=[-1;-1;-3;-2;-3;-1;-2;-3];
The goal is to compare B and D.
if B<D
then it's corresponding value of C will show in F
If B>=D
then its corresponding E value will show in F.
In this case, the answer is
F=[1;2;3;2;-3;2;1;-3]
How can I achieve this please

採用された回答

Joel Handy
Joel Handy 2019 年 8 月 14 日
編集済み: Joel Handy 2019 年 8 月 14 日
This is exactly the situation where you want to use logical indexing.
F(B<D) = C(B<D);
F(B>=D) = E(B>=D);
  1 件のコメント
DARLINGTON ETAJE
DARLINGTON ETAJE 2019 年 8 月 16 日
Thank you Joel...you really saved me...you are the best.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by