GUI handles not updating with guidata
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Greg
le 19 Jan 2018
Modifié(e) : Greg
le 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?
Réponses (0)
Voir également
Catégories
En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!