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

27 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

Jeremy
Jeremy am 9 Apr. 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 Kommentare
Khan Yu
Khan Yu am 10 Apr. 2021
Bearbeitet: Khan Yu am 10 Apr. 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 am 12 Apr. 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?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Create Large-Scale Model Components finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by