Saving variable of selected value from simulink matlab fcn to workspace

조회 수: 6 (최근 30일)
yida
yida 2013년 8월 8일
Hi, I need to save a variable's value from a Matlab fcn block in simulink into workspace for use. But I only want to save the value under certain condition, so there's a IF statement , so something like ias_temp=0;
if(...)
ias_temp=input;
save ias_temp into workspace;
end
it's sort of like to create a memory where you can store a value and hold it over there until you rewrite to it next time.
In addition, I will be using the variable in the Matlab fcn block also, so I need to read the value saved in workspace.
Is there any way to do this? I've tried a lot of ways but they don't work as I wanted it.
Thanks!
yida

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 8월 8일
assignin('base','variable_name',your_fcn_variable)
  댓글 수: 1
yida
yida 2013년 8월 8일
Hi Azzi, it seems to be working. except for that a eml.extrinsic('assignin') needed to be added. So in addition, how can you retreive the value?
Thank you!

댓글을 달려면 로그인하십시오.


Kaustubha Govind
Kaustubha Govind 2013년 8월 8일
Is there a reason the value needs to be stored to the MATLAB workspace? You could either use a persistent variable if the value will only be used in the MATLAB Function block, or to share the data globally, see Share Data Globally.
  댓글 수: 2
yida
yida 2013년 8월 9일
Hi Kaustubha, I tried the persistent variable, but it does not work. I have to store it somewhere else. Otherwise, it is just gonna either be overwritten by values I don't want or it will create error which says something like variable not defined in all executive paths...
Kaustubha Govind
Kaustubha Govind 2013년 8월 9일
yida: Could you paste some sample code on how you are using the persistent variable?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by