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

8 views (last 30 days)
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?
  2 Comments
Oliver Woodford
Oliver Woodford on 23 Jan 2019
Is this already ansewered here?: https://www.mathworks.com/matlabcentral/answers/714-how-can-i-change-the-current-axes-in-a-gui
John Hunt
John Hunt on 23 Jan 2019
Edited: John Hunt on 24 Jan 2019
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
axes(handels.plot);
polarplot(data1(first section, data2)
hold on
polarplot(data1(2nd section, data2) (this is done to achive different colors)
hold on
Axes(handles.a_plot)
plot(data3, data4)
hold on
else
axes(handles.plot);
cla
axes(handels.a_plot);
cla
When I clear the button that is when it breaks and gives the error spoken above.

Sign in to comment.

Accepted Answer

Kevin Chng
Kevin Chng on 24 Jan 2019
Hi,
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])
  3 Comments
Kevin Chng
Kevin Chng on 25 Jan 2019
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.
John Hunt
John Hunt on 25 Jan 2019
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.

More Answers (0)

Categories

Find more on Polar Plots 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!