Function Handle in parsim Input

조회 수: 11 (최근 30일)
Abdel Gafoor Haddad
Abdel Gafoor Haddad 2019년 11월 7일
댓글: FabianJ 2021년 12월 6일
Hello,
If I define a function handle in the workspace as e, then using e(u) in Simulink interpreted function block works with manual simulation.
I would like to do the same but this time with parallel simulations that are called from MATLAB.
Is there a way to have a function handle as the input of parsim? For example I tried the following:
b=@(u)(u);
eval(['b=@(u)([' 'u(1)+2' ']);']);
model = 'simulink_file_name';
load_system(model)
in = Simulink.SimulationInput(model);
in = in.setVariable('e',b); % b is the function handle defined above, and e is the parameter in the interpreted matlab function block
out = parsim(in)
However, this gives the error "Unrecognized function or variable 'e'." I tried also to use e(u) in the block, but another error comes up "Undefined function 'e' for input arguments of type 'double'."
  댓글 수: 1
FabianJ
FabianJ 2021년 12월 6일
Did you solve the problem?

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

답변 (1개)

Walter Roberson
Walter Roberson 2019년 11월 7일
No, Interpreted MATLAB Function cannot handle function handles, at least not directly. You should be setting the Interpreted Function Block's MATLABFcn property to the appropriate character vector before starting the parsim()
It just might work to have the Intrpreted MATLAB Function invoke a name that you had set to a function handle, such as if the block was coded as b(u) and you had set b to a function handle. You might need to use parfevalOnAll to write the function handle into all of the pool members.
  댓글 수: 1
Abdel Gafoor Haddad
Abdel Gafoor Haddad 2019년 11월 7일
Thank you for your reply. Yes, it actually works by invoking the name set as function handle.
I'm trying to do the same but with parsim to simulate the model for many different function handles. Unfortunately, parfevalOnAll did not solve the problem.

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

카테고리

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

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by