フィルターのクリア

Import date data from excel

19 ビュー (過去 30 日間)
Sayantan Sahu
Sayantan Sahu 2018 年 1 月 18 日
回答済み: Peter Perkins 2018 年 1 月 18 日
I have an excel sheet with two columns. The first column has the date in the format mmm-yy and the second column has the values.
Column A Column B Jan-05 Value Feb-05 Value Mar-05 Value
I imported the dates successfully as,
month_year=xlsread('Filename','A2:A133'); formatOut = 'mmm-yy'; month_year = datestr(month_year,formatOut)
The output month_year is of 'char' type of 132x6.
I wish to plot with x-axis being month_year and y-axis the corresponding values. So I write something like,
month_year=datenum(month_year,'mmm-yy') plot(month_year, data) datetick('x','mmmyyyy','keepticks','keeplimits')
However in the process all the dates in the x-axis are now 'Jan 00'
How do I solve this ?

採用された回答

Peter Perkins
Peter Perkins 2018 年 1 月 18 日
Unless you are using an older version of MATLAB, you are likely much better of using readtable to read your data into a table, converting the date text into a datetime (if necessary, depends on what version of MATLAB you're using and how the spreadsheet is set up), and plotting the vales vs. the datetimes.
Let's assume readtable gives you a table something like this:
>> t = table({'Jan-05';'Feb-05';'Mar-05'},[1;2;3],'VariableNames',{'A' 'B'})
t =
3×2 table
A B
________ _
'Jan-05' 1
'Feb-05' 2
'Mar-05' 3
Do this:
>> t.A = datetime(t.A,'InputFormat','MMM-yy')
t =
3×2 table
A B
___________ _
01-Jan-2005 1
01-Feb-2005 2
01-Mar-2005 3
>> plot(t.A,t.B)
If you need to tinker with the x axis ticks or labels, here's where to find them:
>> h = gca;
>> h.XAxis
ans =
DatetimeRuler with properties:
Limits: [01-Jan-2005 05-Mar-2005]
TickValues: [01-Jan-2005 15-Jan-2005 29-Jan-2005 12-Feb-2005 26-Feb-2005]
TickLabelFormat: 'MMM dd'
Show all properties

その他の回答 (1 件)

KSSV
KSSV 2018 年 1 月 18 日
Use this:
[num,txt,raw] = xlsread(myfile) ;
  1 件のコメント
Sayantan Sahu
Sayantan Sahu 2018 年 1 月 18 日
The num file imports the dates as integer numbers. In that case how would I plot it on x-axis so that it shows something like 'Jan-05'

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

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by