Help with exporting variables from function to workspace to then run in simulink file
24 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have a function where I assign values to variables and then open a simulation and run it using those variables. I am using a function so that I can pick and choose which simulations I am running but although the simulations are within the function it doesn't recognise that they are there. Attached code below:
function IGBT_MOSFET = Sim_IGBT(n)
if n == 'On'
Vth_MOSFET = 3.8;
Vth_IGBT = 6.2;
Vf = 1.8;
R_on_MOSFET = 18e-3;
R_on_IGBT = 72.5;
E_on_MOSFET = 1100e-6;
E_off_MOSFET = 180e-6;
V_off_MOSFET = 800;
I_on_MOSFET = 42;
E_on_IGBT = 2.7e-3;
E_off_IGBT = 1.1e-3;
V_off_IGBT = 600;
I_on_IGBT = 40;
% open('Coursework_part_4_sim_IGBT.slx')
% open('Coursework_part_4_sim_MOSFET.slx')
% sim('Coursework_part_4_sim_IGBT.slx')
% sim('Coursework_part_4_sim_MOSFET.slx')
else
end
end
0 Commenti
Risposte (2)
Paul
il 3 Dic 2025 alle 21:30
The "modern" way to do this with the sim command is to use a Simulink.SimulationInput as the input. See that doc page to get started, particularly the link to setVariable. Also, use the output argument form of sim.
0 Commenti
Fangjun Jiang
il 3 Dic 2025 alle 15:23
Modificato: Fangjun Jiang
il 3 Dic 2025 alle 15:24
You will need to use assignin('base','Vth_MOSFET',3.8) etc. to make this work.
Your current code assigns the variables and their values in the function workspace, while your Simulink model most likely uses the variables in the base workspace.
It will be inconvenient to have so many assignin() statements. The other way is to save these variables in a .m file and run evalin('base','Mfile')
0 Commenti
Vedere anche
Categorie
Scopri di più su Programmatic Model Editing 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!