GUI handles not updating with guidata
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(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!