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

조회 수: 22 (최근 30일)
Khan Yu
Khan Yu 2021년 4월 9일
댓글: Jeremy 2021년 4월 12일
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에서 Create Large-Scale Model Components에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by