Won't show me my variable?

조회 수: 4 (최근 30일)
Frane
Frane 2021년 8월 24일
편집: Frane 2021년 8월 24일
Hello,
So when I run the code I don't get my variable "I" on the right side. The variable is in the following part od the code:
if Ms >=3.5
I = 21.29 * Ms - 69.4;
elseif Ms >= 2
I = 2.73 * Ms - 4.47;
elseif Ms >= 0
I = 0.5 * Ms;
elseif Ms >= (-2)
I = 0.5 * Ms;
elseif Ms >= (-3.5)
I = 2.73 * Ms + 4.47;
elseif Ms < (-3.5)
I = 21.29 * Ms + 69.4;
end
What could be the problem?
  댓글 수: 2
Stephen23
Stephen23 2021년 8월 24일
편집: Stephen23 2021년 8월 24일
"What could be the problem?"
Ms is non-scalar, and contains false values.
The MATLAB approach is to use logical indexing, not IF/ELSEIF/END.
Frane
Frane 2021년 8월 24일
What can I change to fix it?

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

채택된 답변

Stephen23
Stephen23 2021년 8월 24일
"What can I change to fix it?"
Use logical indexing, e.g.:
I = 0.5 * Ms;
X = Ms>=3.5;
I(X) = 21.29 * Ms(X) - 69.4;
X = Ms>=2 & Ms<3.5;
I(X) = 2.73 * Ms(X) - 4.47;
X = Ms<(-2) & Ms>=(-3.5)
I(X) = 2.73 * Ms(X) + 4.47;
X = Ms<(-3.5);
I(X) = 21.29 * Ms(X) + 69.4;
  댓글 수: 1
Frane
Frane 2021년 8월 24일
편집: Frane 2021년 8월 24일
It worked.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 System Composer에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by