Undefined function or variable 'inputParser' while using Matlab Function in Stateflow
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Christian Black
le 4 Juin 2020
Commenté : Christian Black
le 2 Juil 2020
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 commentaires
Ameer Hamza
le 5 Juin 2020
Good that this solution worked. I have added this as an answer with modification to make it work. Thanks.
Réponse acceptée
Ameer Hamza
le 5 Juin 2020
Modifié(e) : Ameer Hamza
le 5 Juin 2020
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
'get' is needed as extrensic to extract data from p.Results as shown in comment: https://www.mathworks.com/matlabcentral/answers/542015-undefined-function-or-variable-inputparser-while-using-matlab-function-in-stateflow#comment_884843
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Event Functions dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!