How can i generate .m file for a given simulink model?

1 Ansicht (letzte 30 Tage)
Aditi
Aditi am 23 Jul. 2023
Kommentiert: Aditi am 26 Jul. 2023
So i have basically modeled a BLDC motor in simulink for my project. But now i need to model the same in matlab. So is there a way in which i can directly generate the .m file for my Simulink model?

Antworten (3)

Angelo Yeo
Angelo Yeo am 23 Jul. 2023
Unfortunately, there is no such a functionality to generate an equivalent m-file out of a Simulink model.

Sam Chak
Sam Chak am 23 Jul. 2023
Bearbeitet: Sam Chak am 23 Jul. 2023
What kind of code do you expect to see in the m-file? If you want to extract some information related to the system that you modeled in Simulink, in your case, the BLDC motor, then it may be possible to obtain a linear approximation (state-space model) of the Simulink model using the linearize() command. For more info, please refer to the documentation:
From the state-space model, you can write a simple script to simulate the linearized model over a small operating range, either using step(), lsim(), impulse(), or even an ode solver such as ode45().
If you know the exact math that describes the behavior of the motor, then you can write the ode function file for the motor. See the example below:
function xdot = pmstepper(t, x)
xdot = zeros(4, 1);
% parameters
B = ...;
Kb = ...;
I = ...;
Rt = ...;
R = ...;
L = ...;
K1 = B/I;
K2 = Kb/I;
K3 = Rt;
K4 = Kb/L;
K5 = R/L;
va = ...;
vb = ...;
% state-space
xdot(1) = x(2);
xdot(2) = - K1*x(2) - K2*x(3)*sin(K1*x(3)) + K2*x(4)*cos(K1*x(3));
xdot(3) = K4*x(2)*sin(K1*x(3)) - K5*x(3) + 1/L*va;
xdot(4) = - K4*x(2)*cos(K1*x(3)) - K5*x(4) + 1/L*vb;
end
  1 Kommentar
Aditi
Aditi am 25 Jul. 2023
I do have a set of equations that describes the working of my motor.
Thank you for the link. I shall check it out.

Melden Sie sich an, um zu kommentieren.


Steven Lord
Steven Lord am 25 Jul. 2023
Do you need to generate a MATLAB function file or do you just need to be able to simulate the model from MATLAB code? If the latter you can do that.
  1 Kommentar
Aditi
Aditi am 26 Jul. 2023
I need to generate a matlab function file.
Basically I want my matlab program to behave as a BLDC motor.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Specialized Power Systems finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by