How to plot a graph in GUI by passing function

3 ビュー (過去 30 日間)
Bharath 2015 年 12 月 18 日
コメント済み: Walter Roberson 2015 年 12 月 21 日
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)
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],...
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)
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',...
'Value',0,'Units','Normalized','Position',[0.45 .90 0.07,0.04],...
handles.haxes = axes('Units','Normalized','Position',[.05,.1,0.90,0.38],...
% Move the GUI to the center of the screen.
% Make the GUI visible.
handles.f.Visible = 'on';
%%call back function for Push button Prepar_Geom
function [] = tb1_Callback(varargin)
  2 件のコメント
Geoff Hayes
Geoff Hayes 2015 年 12 月 18 日
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
but not the line that precedes it (which references handles.haxes as well).
Bharath 2015 年 12 月 21 日
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.



Walter Roberson
Walter Roberson 2015 年 12 月 21 日
You need to do the assignment to handles.haxes before the assignment to handles.tb1 . See the explanation in
  2 件のコメント
Bharath 2015 年 12 月 21 日
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
What is the imporatance of eventdata and hobject? Can also we define the function as


その他の回答 (0 件)


Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by