Function 'subsindex' is not defined for values of class 'matlab.graphics.GraphicsPlaceholder'
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Bob Blaine
2017-7-21
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 个评论
Bob Blaine
2017-8-4
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Maintain or Transition figure-Based Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!