I have the error "Unexepected Matlab expression", how can I solve it ?
3 views (last 30 days)
Show older comments
Hi everyone, I'm trying to build a custom block with the following code :
component pelton_turbine
% Ce composant calcule le couple généré par l'eau sur la turbine.
% 🔹 Déclaration des ports
nodes
H = foundation.hydraulic.hydraulic; % Port hydraulique
R = foundation.mechanical.rotational.rotational; % Port mécanique rotatif
end
% 🔹 Déclaration des paramètres
parameters
eta = {0.85, '1'}; % Rendement de la turbine
rho = {1000, 'kg/m^3'}; % Densité de l'eau
r = {0.5, 'm'}; % Rayon moyen de la roue
end
% 🔹 Déclaration des variables internes
variables
T = {0, 'N*m'}; % Couple généré
Q = {0, 'm^3/s'}; % Débit volumique
H_head = {0, 'm'}; % Hauteur d'eau équivalente
end
% 🔹 Bloc des équations
equations
Q == H.q; % Débit entrant dans le port hydraulique
H_head == H.p / (rho * 9.81); % Calcul de la hauteur d'eau équivalente
T == eta * rho * Q * H_head * r; % Formule du couple hydraulique
R.tau == T; % Appliquer le couple sur l’axe mécanique
end
endcomponent
I keep having the same error : Unexepected Matlab expression for the last line ('endcomponent'). I have already checked a lot of sources of error (hidden spaces, checking that the path is good...). Do you have any idea of what might be wrong ?
Thanks in advance,
Nils
0 Comments
Accepted Answer
dpb
on 14 Mar 2025
Edited: dpb
on 14 Mar 2025
equations
Q == H.q; % Débit entrant dans le port hydraulique
H_head == H.p / (rho * 9.81); % Calcul de la hauteur d'eau équivalente
T == eta * rho * Q * H_head * r; % Formule du couple hydraulique
R.tau == T; % Appliquer le couple sur l’axe mécanique
end
In the above the "==" should be "=" for assignment, not equality...
I don't have Simscape, but I expect the problem with
endcomponent
is that like all other blocks construction in MATLAB, the syntax is just
end
For human documentation purposes you could add the "component" to indicate the block as a comment, of course...
end % component
2 Comments
dpb
on 17 Mar 2025
Glad to help.
It would be agoodthing™ to then accept the Answer if it solved the problem...
More Answers (0)
See Also
Categories
Find more on Troubleshooting in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!