Won't show me my variable?

2 views (last 30 days)
Frane
Frane on 24 Aug 2021
Edited: Franeon 24 Aug 2021
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:
ifMs >=3.5
I = 21.29 * Ms - 69.4;
elseifMs >= 2
I = 2.73 * Ms - 4.47;
elseifMs >= 0
I = 0.5 * Ms;
elseifMs >= (-2)
I = 0.5 * Ms;
elseifMs >= (-3.5)
I = 2.73 * Ms + 4.47;
elseifMs < (-3.5)
I = 21.29 * Ms + 69.4;
end
What could be the problem?
2 Comments
Frane
Frane on 24 Aug 2021
What can I change to fix it?

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 24 Aug 2021
"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;

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!