How to load the function (.m) to the workspace when the simulink run?

19 visualizaciones (últimos 30 días)
Could anyone help me out?
i learn radar tracking based kalman filter.
the time when i copy the model to a new space, its some function do not follow the copying.
and the workspace hasnt appeared the variables such as speed delta g
when it run
but how can i load the function aero radplot_dsp when run the simulink?

Respuesta aceptada

Jeremy
Jeremy el 9 de Abr. de 2021
It appears that you are using MATLAB R2021a on Windows.
My understanding of your issue is that you've moved the model to a different directory, and you use a function that defines variables in the workspace, but you do not copy the function into the new directory containing the model.
You could try adding a call to your function in the InitFcn callback of your model:
  • Right click on the Simulink canvas and click Model Properties (near the bottom)
  • Click Callbacks
  • Click InitFcn
  • In the box on the right, add a call to your function. You can use run and fullfile to call a function which is not on the MATLAB path or in the current working directory. For example:
run(fullfile('C:\work\create_vars'))
  • Note that if your function is on the path, you do not need to use run and fullfile, you can just call it directly, like:
create_vars
  • Click OK
This will cause the files you call to run every time you simulate the model. If you do not want it to run every time you simulate the model, you could call the functions manually instead.
  2 comentarios
Khan Yu
Khan Yu el 10 de Abr. de 2021
Editada: Khan Yu el 10 de Abr. de 2021
Thank you for helping me, I am a rookie. I still can't get results.it still doesn't work.
i guess it may caused by the mat./m. ,the 'aero_raddat_dsp' is a function ,but not a file .so ' full (file()) ' looks inapproriate.
May i get more help ?
Thanks!
Jeremy
Jeremy el 12 de Abr. de 2021
It looks like your function is not on the MATLAB path. I think you need to give the full path to your function instead of just the filename. To find the path you can navigate to the directory that contains your function and type
which aero_raddat_dsp
This gives you the full path to the file that you can provide to the run(fullfile()) command.
For example, I type which plot and I get:
The text D:\MATLAB\R2021a\toolbox\matlab\graph2d\plot
is the full path to the plot function.
Does this help?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Create Large-Scale Model Components en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by