Clear Filters
Clear Filters

if statement inside for loop location issues

3 views (last 30 days)
Imagine this
A=[B C D E];
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
How can I achieve this please

Accepted Answer

Joel Handy
Joel Handy on 14 Aug 2019
Edited: Joel Handy on 14 Aug 2019
This is exactly the situation where you want to use logical indexing.
F(B<D) = C(B<D);
F(B>=D) = E(B>=D);

More Answers (0)

Community Treasure Hunt

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

Start Hunting!