GUI handles not updating with guidata

1 次查看(过去 30 天)
TJ
TJ 2018-1-18
编辑: Greg 2018-1-19
Hi all,
I have a GUI which initialises with:
handles.histFig = gobjects(0); % Return empty graphics array object
handles.histAxes = gobjects(0); % Return empty graphics array object
guidata(hObject, handles);
I then have a call back function for a push button which either creates a set of axes in a figure window (separate from the GUI) or if it exists I want to update the figure with data and hence add more lines onto the axes. Once I step out of the callback the axes saved in handles vanished. The code:
function pushbutton_get_Callback(hObject, eventdata, handles)
if isempty(handles.hAxes) || ~isgraphics(handles.hAxes)
handles.hFig = figure();
handles.hAxes = axes('Parent', handles.hFig);
handles.v(1) = line(handles.hAxes, [0.000001,1], [90, 90], 'DisplayName', '90 kV', 'Color','red','LineStyle','--', 'LineWidth', 1.5);
handles.v(2) = line(handles.hAxes, [0.000001,1], [100, 100], 'DisplayName', '100 kV','Color','blue','LineStyle','--', 'LineWidth', 1.5);
xlabel(handles.hAxes, '% Distribution');
ylabel(handles.hAxes, 'pk - pk Voltage [kV]');
set(handles.hAxes, 'xscale','log', 'xlim',[0.000001,1], 'ylim', [70, 110],...
'XGrid', 'On', 'YGrid', 'On', 'NextPlot', 'add');
title(handles.hAxes,['IEP ',trainForm3], 'FontSize',14); %
end
fileNames = cellstr(get(handles.textFile,'String'));
file = fileNames{get(handles.textFile,'Value')};
v = abs(handles.finalData(2,:).'/1000);
[counts, edges]=histcounts(v, 'BinLimits', [0, 120],...
'BinWidth', 0.2, 'Normalization', 'probability');
binCentres = 0.5*(edges(1:end-1) + edges(2:end));
numPlots = numel(get(handles.histAxes, 'Children'));
handles.voltHist(numPlots + 1)= stairs(handles.hAxes, counts*100, binCentres, 'DisplayName', file);
lgd= legend(handles.hAxes, 'Location','southoutside','Orientation','horizontal');
guidata(hObject, handles);
So when I run the callback again, instead of the graph being updated with the new data stored in finalData, it creates a new plot.
I am not sure how to link the figure data to the GUI so that when I run the GUI callback it updates the figure by storing the values of handles.hAxes and handles.hFig. I do not see why it is not doing that if I am saving these in the handles structure.
Any pointers would be appreciated.
Cheers
  3 个评论
TJ
TJ 2018-1-18
The callback is triggered from the GUIDE created GUI. The figure that opens up in a seperate figure window which contains only a set of axes.
Greg
Greg 2018-1-19
编辑:Greg 2018-1-19
You initialize handles.histAxes then use handles.hAxes in the callback, but that should result in Reference to non-existent field errors...
If you put a breakpoint at the top of the callback, what does it say handles.hAxes contains on the first and second executions?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by