10

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)?

6
  • can you please share where does it practically needs to do? it seems to be quiet interesting though you have both the vectors ready in your hand...
    – noufal
    Apr 22, 2013 at 4:04
  • Are you saying that you no longer have x and y in memory?
    – Dan
    Apr 22, 2013 at 6:47
  • @noufal I am using a GUI of which I have limited control (I am not allowed to fundamentally alter its structure although I can add on to it). The GUI spits out the plot with the axes arranged in a particular way of which I need the opposite. Since I have limited control over the GUI itself this is the only option... Apr 22, 2013 at 19:35
  • @dan Yes, I do have them in memory. Apr 22, 2013 at 19:35
  • If they are in memory then why not just go plot(y,x)?
    – Dan
    Apr 23, 2013 at 6:19

1 Answer 1

9

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.