Function 'subsindex' is not defined for values of class 'matlab.graphics.GraphicsPlaceholder'
6 views (last 30 days)
Show older comments
I have the following Figure
classdef gui < matlab.apps.AppBase
...
function app = gui
% Construct app
end
...
properties (Access = public)
myFuncRef = @myFun
end
...
function myFun(app)
% do something
end
...
end
in which I have defined the method
myFun
If the Figure is running, that is it's showing a window, how can I invoke the method "MyFun" from the Command Window of MATLAB or MATLAB Fcn Block in Simulink ? In the simulink I tried with
h = findobj(0, 'type', 'figure');
funcRef = get(h, 'myFuncRef');
funcRef(h);
but I get the error
An error occurred while running the simulation and the simulation was terminated Caused by: Function 'subsindex' is not defined for values of class 'matlab.graphics.GraphicsPlaceholder'.
Thanks in advance!
0 Comments
Answers (1)
Bob Blaine
on 21 Jul 2017
Hi tahec,
The error message is telling you that findobj didn't find any figures on the graphics root, and couldn't resolve the function call. If you open MATLAB with no graphics and just execute your "h = ..." block of code you will get that error.
AppBase is the base class for an App Designer application and usually contains a UIFigure, which is what shows up on the screen. Even if you are creating a UIFigure in the constructor, it won't show up in a findobj, but it will show up in findall:
h = findall(0,'type', 'figure')
That will get you halfway there. One other thing you will have to do is put a handle to the gui object in the UIFigure's UserData property. You can then call its function:
if ~isempty(h) then
h.UserData.myFun()
end
Having said all of this, I'm hoping that this is for debugging, or fiddling with a parameter. You'd probably want to code something into the graphics GUI as a permanent functionality.
3 Comments
Bob Blaine
on 4 Aug 2017
Hi tahec,
Sorry about being a little vague, but based on the code you posted, I was assuming that you were constructing the UIFigure in the constructor of your gui object the way App Designer does:
classdef MyObject < matlab.apps.AppBase
properties
UIFigure matlab.ui.Figure
end
methods
function gui = MyObject
gui.UIFigure = matlab.ui.Figure;
% Set the Userdata on the UIFigure to gui
gui.UIFigure.UserData = gui;
end
end
end
If you aren't creating a UIFigure, then I'm not sure where you can get a handle to your gui object. That may require someone more Simulink savvy to help you out.
See Also
Categories
Find more on Maintain or Transition figure-Based Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!