Undefined function or variable 'inputParser' while using Matlab Function in Stateflow

조회 수: 10 (최근 30일)
Hello all,
I'm using a matlab function within my stateflow diagram, however I'm getting the error "Undefined function or variable 'inputParser'". When I try to run the function within a .m file it works fine. I cannot find any limitations to inputParser usage in stateflow within the help files or by google.
Code:
function x = OK(i)
default = 1:50;
p = inputParser;
addOptional(p,'i',default);
parse(p,i);
if all(Input_Mux(i)== enumState.OK)
x = true;
else
x = false;
end
end
Does anyone know why this is failing?
  댓글 수: 6
Ameer Hamza
Ameer Hamza 2020년 6월 5일
Good that this solution worked. I have added this as an answer with modification to make it work. Thanks.
Christian Black
Christian Black 2020년 7월 2일
Update for anyone else who finds this post:
The above solution works well to run Simulink natively, however if you wish to use code generation for either running on dedicated hardware or for using reference models in a large simulink model you are unable to do so as the coder is unable to parse extrinsic functions.

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

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 6월 5일
편집: Ameer Hamza 2020년 6월 5일
It seems that the problem might be happening because the inputParser does not support code generation. You may try coder.extrinsic
coder.extrinsic('inputParser', 'addOptional', 'parse', 'get')
add this line at beginning of function definition
function x = OK(varargin)
coder.extrinsic('inputParser', 'addOptional', 'parse', 'get')
Input_mux = [1:100]; %Would normally be stateflow input, added here for ease.
default = 1:50;
p = inputParser;
addOptional(p,'i',default);
parse(p,varargin{:});
if all(Input_mux(p.Results.i)== 5)
x = true;
else
x = false;
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Event Functions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by