Simulink InitFCN in MATLAB function2 block does not initialize object from h = fill()
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Stijn Klevering
le 24 Nov 2020
Commenté : Stijn Klevering
le 11 Jan 2021
Hello,
I am receiving real-time data, which I want to plot using the fill() function in a MATLAB function2 block. First I initialize the figure in InitFCN by:
coder.extrinsic('fill')
figure(1);
%Basic properties of figure
axis([-0.2 0.2 -0.2 0.2]);
%Plot Object
Rectanglex = [0.005, -0.005, -0.005, 0.005];
Rectangley = [-0.03, -0.03, -0.07, -0.07];
Object = fill(Rectanglex, Rectangley, 'b');
Afterwards I want to change the object in the function by:
set(Object,'XData',Rectanglex,'YData',Rectangley);
drawnow;
The error I get in simulink is:
Undefined function or variable 'Object'. Function 'MATLAB Function2' (#88.1786.1792), line 78, column 5: "Object" Launch diagnostic report.
And the error I get in the Matlab command window:
Error using matlab.graphics.primitive.Patch/set
Invalid or deleted object.
I hope anyone can explain Why my object is deleted after initializing it?
If you need more info I am happy to upload it.
Regards
0 commentaires
Réponse acceptée
Uday Pradhan
le 6 Jan 2021
Hi Stijn,
It is my understanding that you are using the first script as the InitFcn callback of your function block, then later in the function block you want to access the figure object created by the InitFcn script.
In this case, you can check that the variables defined in the InitFcn (Rectanglex,Object,etc) are all stored in the base workspace and hence the function defined by your block cannot access it directly. Hence the error pops up while you simulate the model. As a workaround you can consider using evalin function in your function block to access the required variables. As and example, see:
function MATLABFunction2(..)
coder.extrinsic('evalin');
obj = evalin('base','Object');
...
set(obj,...)
end
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Programmatic Model Editing 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!