How to plot a graph in GUI by passing function
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
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
picrotor(model,handles.haxes);
but not the line that precedes it (which references handles.haxes as well).
採用された回答
Walter Roberson
2015 年 12 月 21 日
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Interactive Control and Callbacks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!