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

29 次查看(过去 30 天)
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?

采纳的回答

Jeremy
Jeremy 2021-4-9
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 个评论
Khan Yu
Khan Yu 2021-4-10
编辑:Khan Yu 2021-4-10
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 2021-4-12
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?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Environment Customization 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by