MATLAB Answers


How to switch between plotting on two different axis in one gui function

Asked by John Hunt on 23 Jan 2019
Latest activity Commented on by John Hunt on 25 Jan 2019
I have a data set that includes 25 sets of time, position x, y,z forces, and torque. I am using a GUI to access all of the data and plot a portion of any two of the columns on a single plot that updates with a slider bar. I have gotten that to work great, however I now want to be able to have a second plot that will plot data similar to the first and update in the same slide bar. I am having trouble switching from one plot to the other and the data updates on the most recent plot. How can I switch between these two?


Is this already ansewered here?:
So I have tried this. But an error comes up that says "Invalid axes handle". I have some logic that determines which data is plotted and before each plot I have the line axes(handles.axes2);
for which plot I want to plot on, but if I try to plot to the same axes that was used last I get that error.
It will work once but then the second time it throws that error.
a simple pseudo code for this program is as follows
load data sets and put them in handles
dropdown menus for what data
% - radio buttton -
if button is 1
if certian drop down options are loaded
polarplot(data1(first section, data2)
hold on
polarplot(data1(2nd section, data2) (this is done to achive different colors)
hold on
plot(data3, data4)
hold on
When I clear the button that is when it breaks and gives the error spoken above.

Sign in to comment.

1 Answer

Answer by Kevin Chng on 24 Jan 2019
 Accepted Answer

Put the name of your axes in the first argument of your function plot. Example :
plot(handles.axes1,[0 1],[0 1])
plot(handles.axes2,[0 3],[0 1])


Thank you for answering. After some debugging I have found that I am deleting the axes information becuase I am using the polarplot function. Example:
if radio button is on
polarplot(data1, data2)
if radio button is off
After it plots the polarplot handles.axes1 is "deleted"
ans =
handle to deleted Axes
Is there a way that I can do a polar plot with without deleting the handles axes info?
I'm not sure with your application, have you closed any figure? The axes might be in the figure, then later closed by you.
Therefore, the axes is deleted.
I have figured it out. The plot was made with cartesian so when I called for a polarplot the handles.axes1 was deleted to support the new one. So after plotting I assigned the handles.axes1 to the current gca and updated my handles. This is working great. Thanks

Sign in to comment.