フィルターのクリア

Reverse order of X axis

119 ビュー (過去 30 日間)
Marco Piazza
Marco Piazza 2022 年 6 月 23 日
コメント済み: Dyuman Joshi 2022 年 6 月 24 日
Hi everybody, I'm trying to plot the price of an option against time to expiration time in days (in positive integer ofc). But I need to reverse the time. More specifically, I have 15 daily prices so what I did was building a vector from 0 to 15 and use flipr to reverse the order of my raw vector but it doesn't work because also the price of the option was reversed.
Exp = [0:15]; %days to expiration
P = rand(1,15); %fake daily prices
plot(Exp,P) %is all reversed not just the days to expiration
I also tried with set Xdir as follows
Exp = [0:15]; %days to expiration
P = rand(1,15); %fake daily prices
plot(Exp,P)
set(gca, 'Xdir', 'reverse') %again is all reversed not just the days to expiration
Does anyone have a solution to this issue?
Thanks a lot in advace,
Best,
Marco.
  9 件のコメント
Dyuman Joshi
Dyuman Joshi 2022 年 6 月 24 日
Something like this @Marco Piazza?
Exp = 0:15; % Days to expiration
P = linspace(10, 30, length(Exp)); % Fake daily prices increasing
y=plot(Exp,P, 'b.-');
ax=xticklabels;
xticklabels(flip(ax))
Marco Piazza
Marco Piazza 2022 年 6 月 24 日
編集済み: Marco Piazza 2022 年 6 月 24 日
Yes man, this what exactly what I ment. Thanks a lot, and thanks to all of you!!! Anserw the question so that I can accept it!!!!

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

採用された回答

Dyuman Joshi
Dyuman Joshi 2022 年 6 月 24 日
Building on @Image Analyst's comment, reversing the x-tick labels
Exp = 0:15; % Days to expiration
P = linspace(10, 30, length(Exp)); % Fake daily prices increasing
y=plot(Exp,P, 'b.-');
ax=xticklabels;
xticklabels(flip(ax))
  2 件のコメント
Marco Piazza
Marco Piazza 2022 年 6 月 24 日
Thank man, it worked!
Dyuman Joshi
Dyuman Joshi 2022 年 6 月 24 日
You are welcome!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFinancial Toolbox についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by