transform text data like {'1951:Q4'} with quarterly dates to number x axis of a plot

8 ビュー (過去 30 日間)
I read this series fdate in xlsread:
[x,fdate,raw] = xlsread('C:/Users/Owner/Documents/Research/Data/USTreasury/Z1_FL210/z1_csv_files/csv/Z210finaccts.xlsx','A27:J305');. I define fdate1 = fdate(:,1) and get the following column vector:
{'1951:Q4'}
{'1952:Q1'}
{'1952:Q2'}
{'1952:Q3'}
{'1952:Q4'}
{'1953:Q1'}
{'1953:Q2'}
{'1953:Q3'}
{'1953:Q4'}
{'1954:Q1'}
{'1954:Q2'}
{'1954:Q3'}
{'1954:Q4'}
{'1955:Q1'}
{'1955:Q2'}
datetick('x', 'YYYY:QQ','keepticks')
How can I use/transform this column vectors to plot on the x axis in this line of code:
plot (fdate1,x(:,3:4),'LineWidth',1) %1951Q4
I get 'Error using plot Invalid data argument'
Thank you

採用された回答

Kelly Kearney
Kelly Kearney 2021 年 10 月 8 日
I'd recommend converting your fdate cell array to an array of datetimes:
fdate = datetime(fdate, 'InputFormat', 'uuuu:''Q''Q');
From there, you should be able to plot as needed.
  1 件のコメント
Nancy Hammond
Nancy Hammond 2021 年 10 月 11 日
Thank you so much, Kelly. I needed the answer instantly! Apologies for late reply, I kept working away coding

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTime Series Objects についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by