필터 지우기
필터 지우기

Is there a way to share a variable between simulink and matlab?

조회 수: 3 (최근 30일)
Simon
Simon 2015년 8월 21일
댓글: Walter Roberson 2015년 8월 22일
Hi guys, I have a question about simulink and matlab interference. I run a simulink model and m file simultaneously and I need to get the value of a variable from sim model to forward the progress of m file. I'm wondering if there's a way to let simulink and m file share a variable and make it accessible to the m file so that m file can reacts to the variable's changes.
Thank you

채택된 답변

Walter Roberson
Walter Roberson 2015년 8월 21일
편집: Walter Roberson 2015년 8월 22일
Sounds to me as if you should use a MATLAB Function Block with a Trigger Block
  댓글 수: 2
Muthu Annamalai
Muthu Annamalai 2015년 8월 21일
@Simon - you can use a MATLAB Function block to evalin base workspace as a quick-n-dirty way of doing things. See doc :
Walter Roberson
Walter Roberson 2015년 8월 22일
That would depend upon whether Simulink was started from the graphics menu or from sim() . If it was from sim() then it is not writing to the base workspace even with a To Workspace block. A MATLAB Function Block that is reading from the base workspace might not be much use. A MATLAB Function block that was passed the signal and used assignin('base') might be useful though.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2015년 8월 21일
You should use a To Workspace Block
When I investigated earlier this week I discovered that the data is written to the Base workspace if Simulink is started from the graphics menu, but if you call sim() within MATLAB then the data is written to the workspace of the function that calls sim(). (That function can then write it elsewhere.)
  댓글 수: 3
Purushottama Rao
Purushottama Rao 2015년 8월 22일
I think you can use a embedded matlab function available in simulink. In your application, input for the embedded matlab function could be the peak of the external sensor signlas and then you can write a script inside it to call one more function conditionally..
Walter Roberson
Walter Roberson 2015년 8월 22일
"embedded matlab function" is an older term. The newer is MATLAB Function Block

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by