GUI handles not updating with guidata

1 回表示 (過去 30 日間)
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); %
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.
  3 件のコメント
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 Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by