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

3 visualizzazioni (ultimi 30 giorni)
Aditi
Aditi il 23 Lug 2023
Commentato: Aditi il 26 Lug 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?

Risposte (3)

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

Sam Chak
Sam Chak il 23 Lug 2023
Modificato: Sam Chak il 23 Lug 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 Commento
Aditi
Aditi il 25 Lug 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.

Accedi per commentare.


Steven Lord
Steven Lord il 25 Lug 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 Commento
Aditi
Aditi il 26 Lug 2023
I need to generate a matlab function file.
Basically I want my matlab program to behave as a BLDC motor.

Accedi per commentare.

Categorie

Scopri di più su Specialized Power Systems in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by