필터 지우기
필터 지우기

if statement inside for loop location issues

조회 수: 3 (최근 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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by