if statement inside for loop location issues
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!