Refreshdata for plot in GUI Axes

5 次查看(过去 30 天)
I made a guide GUI with an axes plot, an editable table, and several callback functions. I have been beating my head against the wall trying to figure out how to get the plot to update (ala refreshdata) when the user edits the data in the table. I currently have the plot redrawing completely each time table data is edited, but that isn't ideal because I'd like to be able to, for example, zoom in on the plot while the data is being edited and have it stay zoomed in.
The GUI code is 1380 lines and counting so I won't post it here, but below is a simplified version of one of the things I've tried (that doesn't work) and I'd be happy to send the code to anyone interested in helping me out. This is only my 3rd week matlabbing so sorry if I overlooked somewhere that this has already been answered.
function varargout = GUITrial(varargin)
...initialization code
end
function GUITrial_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
x=1:10;
handles.vals=[x' x'.^2 1.1.*x'.^2];
set(handles.uitable1,'Data',handles.vals);
handles.line1=plot(handles.axes1,handles.vals(:,1),handles.vals(:,2),'YDataSource','handles.vals(:,2)','Color','r');
hold on;
handles.line2=plot(handles.axes1,handles.vals(:,1),handles.vals(:,3),'YDataSource','handles.vals(:,3)','Color','b');
hold off;
guidata(hObject, handles);
end
function uitable1_CellEditCallback(hObject, eventdata, handles)
handles.vals=get(handles.uitable1,'Data');
guidata(hObject,handles);
refreshdata(handles.line1);
refreshdata(handles.line2);
end

采纳的回答

Jarrod Rivituso
Jarrod Rivituso 2011-4-1
For 3 weeks in you seem quite competent! :)
One thought I just had is to try setting the 'ydata' property explicitly...
>> ph = plot(1:10)
>> yValues = get(ph,'ydata')
>> yValues(5) = 6;
>> set(ph,'ydata',yValues)
In a simple test I just did it seemed to work the way you described. You could do a similar thing with the 'xdata', if necessary. I'm not sure why the refreshdata approach doesn't work for you.
Hope this helps!
  1 个评论
Carie Frantz
Carie Frantz 2011-4-3
Yes, that did the trick!
The key was saving plots in the functions that plotted them to the GUI handles struct:
handles.line1=plot(...)
Then after modifying the data in another function, using set to change the values of the plot (assuming the plot is there):
if isfield(handles,'line1')
set(handles.line1,'XData',xdata,'YData',ydata)
end
Thank you!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by