Plotting with two y-axes in a GUIDE GUI

2 次查看(过去 30 天)
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));

回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by