How to use condition to output a new matrix

조회 수: 1 (최근 30일)
Akshay Arora
Akshay Arora 2019년 6월 14일
댓글: Star Strider 2019년 6월 14일
I am using the following statement to
Sim_EVT is 1570x1 (double)
CA is 1570x1(double)
if (Sim_EVT > CB) && (Sim_EVT <(CB+CA)))
ClassB2 = CA.*0.7761194029850746;
else
ClassB2 = 0;
end
I need to output a new matrix of (1570x1) if the condition meets.
I am getting the following error
Operands to the || and && operators must be convertible to logical scalar values.
Error in AssetPathsPlot (line 53)
if ((Sim_EVT > CB) && (Sim_EVT <(CB+CA)))

채택된 답변

Star Strider
Star Strider 2019년 6월 14일
Just use one &:
if (Sim_EVT > CB) & (Sim_EVT <(CB+CA)))
You can probably do ths in one line:
ClassB2 = (CA.*0.7761194029850746).*((Sim_EVT > CB) & (Sim_EVT <(CB+CA)));
Note: I cannot test this, since I do not have your data. It should work.
  댓글 수: 2
Akshay Arora
Akshay Arora 2019년 6월 14일
it works fine, I got the logic too. Thanks for your help.
Star Strider
Star Strider 2019년 6월 14일
As always, my pleasure.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Mobile Fundamentals에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by