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

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 月 4 日
In this function, the result of parse() is not being used. Why not remove those lines?
Hello Ameer, thanks for your feedback. Yes the above didn't match my intention, sorry I'm new to using the inputParser class. I've now corrected the code to reference the parsed input, but I'm still getting this error when the function is used within stateflow.
function x = OK(varargin)
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
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')
add this line at beginning of function definition
function x = OK(varargin)
coder.extrinsic('inputParser', 'addOptional', 'parse')
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
Christian Black
Christian Black 2020 年 6 月 5 日
編集済み: Christian Black 2020 年 6 月 5 日
Thanks Ameer, that is just what I needed. I also found that you could not directly extract the 'Results' feild as you receive an 'mxArray' error so you need to use the get method with a preintialised varible:
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{:});
temp = [0];
temp = get(p,'Results.i')
if all(Input_mux(temp)== 5)
x = true;
else
x = false;
end
end
Thanks again for your help!
P.S Ameer, if you move your above comment to an awnser that I'll accept it. I do not currently have the option.
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 件)

カテゴリ

ヘルプ センター および File ExchangeEvent Functions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by