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

23 vues (au cours des 30 derniers jours)
Khan Yu
Khan Yu le 9 Avr 2021
Commenté : Jeremy le 12 Avr 2021
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?

Réponse acceptée

Jeremy
Jeremy le 9 Avr 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 commentaires
Khan Yu
Khan Yu le 10 Avr 2021
Modifié(e) : Khan Yu le 10 Avr 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 le 12 Avr 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?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Create Large-Scale Model Components dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by