Function 'subsindex' is not defined for values of class 'matlab.graphics.GraphicsPlaceholder'
    12 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
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 comentarios
Respuestas (1)
  Bob Blaine
    
 el 21 de Jul. de 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 comentarios
  Bob Blaine
    
 el 4 de Ag. de 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.
Ver también
Categorías
				Más información sobre Interactive Model Editing en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


