MATLAB: Refreshdata for plot in GUI Axes

guihandlesplotrefreshdataset

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

Best Answer

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!
Related Question