Is it possible for a Simulink block to access variables loaded from a MAT-file in the local workspace of a function?
조회 수: 1 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2011년 1월 28일
편집: MathWorks Support Team
2015년 9월 2일
I have a function in which I load variables from a MAT-file and then start a Simulink model using the SIM function. The function looks as follows:
function startfun
load 'mymatfile.mat'
sim('mymodel');
end
The model contains some constant blocks which use the loaded variables for their "Constant value" parameter. However, running startfun results in the following error:
ERROR: ??? Error using ==> startfun at 4 Error evaluating parameter 'Value' in 'mymodel/Constant': Undefined function or variable 'myvar'.
where myvar is a variable saved in my MAT-file and that I use for the constant value in a constant block.
채택된 답변
MathWorks Support Team
2015년 9월 2일
Simulink blocks like the Constant block read variables from the base workspace. As such, variables loaded in a function's local workspace are invisible to these blocks.
As a workaround, use EVALIN inside your function to load the MAT-file in the base workspace:
function startfun
evalin('base','load mymatfile.mat');
sim('mymodel');
end
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!