How to plot a graph in GUI by passing function

1 visualización (últimos 30 días)
Bharath
Bharath el 18 de Dic. de 2015
Comentada: Walter Roberson el 21 de Dic. de 2015
Hi all,
I've created a GUI where it takes user input and calualtes and plots the results. All the calculation happens in a function called picrotor. This function takes input model and generates a plot.
I've created a push button which has a call back function defined as follows.
function [] = tb1_Callback(varargin)
axes(handles.haxes)
picrotor(model);
end
Now I want this graph to be plotted in the GUI where I defined it by its handle.
handles.haxes = axes('Units','Normalized','Position',[.05,.1,0.90,0.38],...
'Parent',handles.f,'HandleVisibility','callback');
When I try to excecute the above GUI I get an error.
Reference to non-existent field 'haxes'.
Error in sample_gui/tb1_Callback (line 396)
axes(handles.haxes)
Error while evaluating UIControl Callback
Can someone help to fix this error. thanks in adance for your hints and suggestions. I just wanted to put the call the function and display the graph in GUI
My complete Code is as follows.
handles.f = figure('visible','off',...
'Units','Normalized','Position',[25 25 1300 725],...
'numbertitle','off','Name','Simple GUI);
handles.m = uimenu(handles.f,'Label','File');
aboutm = uimenu(handles.m,'Label','About','callback',@about);
docm = uimenu(handles.m,'Label','Documentation','callback',@documentation);
% loadm = uimenu(m,'Label','Load Data','callback','load');
exitm = uimenu(handles.m,'Label','Exit','callback',@exit);
handles.tb1 = uicontrol(handles.f,'Style','pushbutton',...
'String','Prepare_geom',...
'Value',0,'Units','Normalized','Position',[0.45 .90 0.07,0.04],...
'Callback',{@tb1_Callback,handles});
handles.haxes = axes('Units','Normalized','Position',[.05,.1,0.90,0.38],...
'Parent',handles.f,'HandleVisibility','callback');
% Move the GUI to the center of the screen.
movegui(handles.f,'center')
% Make the GUI visible.
handles.f.Visible = 'on';
%%call back function for Push button Prepar_Geom
function [] = tb1_Callback(varargin)
axes(handles.haxes)
picrotor(model)
end
  2 comentarios
Geoff Hayes
Geoff Hayes el 18 de Dic. de 2015
Bharath - can you post more of your code so that we can get a better idea of how your code has been structured? I'm assuming that you are using the programmatic approach to create your GUI rather than using GUIDE. It's strange that the error message seems to have a problem with
picrotor(model,handles.haxes);
but not the line that precedes it (which references handles.haxes as well).
Bharath
Bharath el 21 de Dic. de 2015
Hi Mr. Hayes, Thanks for your reply. Yes, you right I'm using the programmatic approach to create GUI. I modified my code. Please have a look the code. Now, when the picrotor is called it outputs a plot. Now when i try to define the handles.haxes before I call the picrotor, I still get the same error saying handles.haxes is not defined.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 21 de Dic. de 2015
You need to do the assignment to handles.haxes before the assignment to handles.tb1 . See the explanation in http://uk.mathworks.com/matlabcentral/answers/261050-reference-to-non-existent-field#answer_203806
  2 comentarios
Bharath
Bharath el 21 de Dic. de 2015
Thanks for your answer Mr. Walter. I fixed the problem. I was defining axis after pushbutton, thereby I get this error, Now its error. However,I still confused with
callback_function(hObject,eventdata,handles)
What is the imporatance of eventdata and hobject? Can also we define the function as
@callback_function(varargin)?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Interactive Control and Callbacks 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!

Translated by