Plotting with two y-axes in a GUIDE GUI

2 views (last 30 days)
Caleb
Caleb on 12 Aug 2013
I have a simple GUI created in GUIDE with two axes (axes1, axes2) and a pushbutton (pushbutton_plot).
The callback for pushbutton_plot is the following:
% --- Executes on button press in pushbutton_plot.
function pushbutton_plot_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_plot (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% data
x = 0:pi/100:10*pi;
y = sin(x);
z = cos(x);
w = x./x;
% loop
n = numel(x);
% axes1 plot
h(1) = plot(handles.axes1, x(1), y(1));
h(2) = plot(handles.axes1, x(1), z(1));
% axes2 plot
h(3) = plot(handles.axes2, x(1), w(1));
for i = 1:n-1
% axes1
set(h(1), 'XData', x(1:i), 'YData', y(1:i));
set(h(2), 'XData', x(1:i), 'YData', z(1:i), 'color', 'green');
% axes2
set(h(3), 'XData', x(1:i), 'YData', w(1:i), 'color', 'red');
drawnow;
pause(1/10);
end
hold off
The plots are done like this so the graphs appear to be plotting in real-time. This syntax works when I'm using figures, but I can't get two lines to plot in one axes (with two y-axes) in GUIDE.
The error says I have an "invalid or deleted object" and refers to the line
set(h(1), 'XData', x(1:i), 'YData', y(1:i));

Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!