plotting values in in reverse order

I would like to plot my X-axis values in the reverse direction. I mean if they are A= [ 0 1 2 3 4 5 ] Then instead of plotting them from 0 to 5 I would like to plot them from 5 to 0. I did plot(fliplr(x),y);set(gca,'xdir','reverse') and the labels of the x axis are reversed but the data is still plotted in the same direction. How can I reverse the direction in which the data is plotted?
THANKS! (o:
Ester

回答 (1 件)

Star Strider
Star Strider 2015 年 12 月 17 日

23 投票

Set the x-axis direction 'XDir' to 'reverse':
Example:
x = 0:5;
y = 3 + 2*x;
figure(1)
subplot(2,1,1)
plot(x, y)
grid
subplot(2,1,2)
plot(x,y)
set(gca, 'XDir','reverse')
grid

5 件のコメント

Star Strider
Star Strider 2015 年 12 月 17 日
Ester’s ‘Answer’ moved here:
OK (o: Thanks (O:
Ester
Star Strider
Star Strider 2015 年 12 月 17 日
My pleasure!
If my Answer solved your problem, please Accept it.
Ana Gonçalves
Ana Gonçalves 2022 年 8 月 29 日
how do I do it if I want to select an specific figure?
ex:
set(figure(3), 'XDir', 'reverse')
Error using matlab.ui.Figure/set
Unrecognized property XDir for class Figure.
Bruno Luong
Bruno Luong 2022 年 8 月 29 日
編集済み: Bruno Luong 2022 年 8 月 29 日
@Ana Gonçalves 'XDir' is an axes property not figure
Star Strider
Star Strider 2022 年 8 月 29 日
Following up on that —
x = 0:5;
y = 3 + 2*x;
figure(1)
subplot(2,1,1)
plot(x, y)
grid
subplot(2,1,2)
plot(x,y)
grid
Kids = figure(1).Children;
Kids(1).XDir = 'reverse';
NOTE — In this instance (using subplot) the second subplot is the first axes object.
.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeDiscrete Data Plots についてさらに検索

質問済み:

2015 年 12 月 17 日

コメント済み:

2022 年 8 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by