matlab function to simulink error

2 Ansichten (letzte 30 Tage)
arsal javed
arsal javed am 13 Jul. 2022
Kommentiert: Jon am 13 Jul. 2022
here is code for the machine learning function
function y = predictActivity(u)%#codegen
persistent n;
if isempty(n)
n = loadLearnerForCoder('EnsembleModel.mat');
end
y = predict(n,u);
end
whenever i use it on command line it works fine
i make its block in simulink like this
but when run its block in simulink i get many errors like this
plz someone help me in this i have been stuck on this for quite a while
thnx in advance
  1 Kommentar
Jon
Jon am 13 Jul. 2022
It looks like you are using a "MATLAB Function" block.
Can you please provide the code that is inside of that block.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jon
Jon am 13 Jul. 2022
Bearbeitet: Jon am 13 Jul. 2022
I think it looks like you are not using the "MATLAB Function" block correctly.
If you open that block, maybe you just have the single line of code:
function y = PredictActiity(u)
If so, this is not correct. You need to have a body for the function you define, so you would need to have something like
function y = myfun(u)
y = PredictActiity(u)
While the above should work, it would be simpler to use the "Interpreted MATLAB Function" block.
In this case you would double click on the Interpreted MATLAB Fcn block and enter in the dialog where it asks for MATLAB function:
PredictActiity(u)
  2 Kommentare
arsal javed
arsal javed am 13 Jul. 2022
thnx a lot it was very helpful may god bless u
Jon
Jon am 13 Jul. 2022
Glad that helped. Good luck with your project.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by