Won't show me my variable?

1 vue (au cours des 30 derniers jours)
Frane
Frane le 24 Août 2021
Modifié(e) : Frane le 24 Août 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:
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 commentaires
Stephen23
Stephen23 le 24 Août 2021
Modifié(e) : Stephen23 le 24 Août 2021
"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 le 24 Août 2021
What can I change to fix it?

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 24 Août 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;
  1 commentaire
Frane
Frane le 24 Août 2021
Modifié(e) : Frane le 24 Août 2021
It worked.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur System Composer dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by