Filter löschen
Filter löschen

GUI handles not updating with guidata

2 Ansichten (letzte 30 Tage)
TJ
TJ am 18 Jan. 2018
Bearbeitet: Greg am 19 Jan. 2018
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 Kommentare
TJ
TJ am 18 Jan. 2018
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 am 19 Jan. 2018
Bearbeitet: Greg am 19 Jan. 2018
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?

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by