MATLAB Answers

0

How to use condition to output a new matrix

Asked by Akshay Arora on 14 Jun 2019
Latest activity Commented on by Star Strider
on 14 Jun 2019
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)))

  0 Comments

Sign in to comment.

1 Answer

Answer by Star Strider
on 14 Jun 2019
 Accepted Answer

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 Comments

it works fine, I got the logic too. Thanks for your help.
As always, my pleasure.

Sign in to comment.