Suppose I have vectors x and y, I know I can do plot(x,y)
or plot(y,x)
to achieve what I want. However, my question is specifically: If I have a plot already created in a figure as plot(x,y)
, how can I programmatically exchange the horizontal and vertical axes so that effectively I am saying plot(y,x)
?
In Matlab how can I exchange the horizontal and vertical axes of an existing plot
Interesting question +1. The following example shows how to exchange the x
and y
axes of the current figure:
X = (1:100)'; %# Create x axis data
Y = randn(100, 1); %# Create y axis data
plot(X, Y); %# Plot the data
view(-90, 90) %# Swap the axes
set(gca, 'ydir', 'reverse'); %# Reverse the y-axis (Optional step)
Also, a relevant link to Matlab Central is here.
© 2022 - 2024 — McMap. All rights reserved.
x
andy
in memory? – Washstandplot(y,x)
? – Washstand