Add date variable into Xlsread Syntax?? Needs Help!!

2 ビュー (過去 30 日間)
Xiao Tang
Xiao Tang 2012 年 7 月 16 日
Guys I really need some help here!
There are mutiple similar xlsx files mamed after date, '199001.xlsx'(Jan 1990),'199002.xlsx','199003.xlsx'... Those files include data in different dates with accuracy in month.
The first step is to use MATLAB to do manipulate the data in one month/file. Then do a loop(since the manipulation algorithm for each month is the same), and pull out all the results in the same spreadsheet.
I've done the manipulation for one month. My problem right now is:
How can to make the date a variable when using xlsread?
Case 1, when I use
[~, ~, XXX] = xlsread('C:\Users...\199001.xlsx','Sheet1','E3:E502')
How can I make the part '199001' a variable?
Except for adding a variable to xlsread syntax, it is more challenging when '199001' is a date because the series should be:
199001,199002,199003... 199011,199012,199101(not '199013'!),199102...
So it's not a simple i = i+1 loop.
%%%%%%%%%%%%%
Case 2
There is another file called Economics.xls containing Economics information for all months. Part of the whole spreadsheet is like
When the loop comes to '199708' I should read data in Row 2, i.e., 5.54,0.00,2.23.
The code is
XXX = xlsread('C:\...\Economics.xls','Sheet1','B2:D2')
How can I make Row 2 as a variable according to the first column(the date)? It looks like this should be the same variable in Case 1.
Your opinion is very important!

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 7 月 16 日
編集済み: Andrei Bobrov 2012 年 7 月 16 日
case 1
in case: your files from 199001.xlsx to 199108.xlsx
b = diff(datevec({'199001';'199108'},'yyyymm'));
mns = b(1:2)*[12;1];
a = cellstr(datestr(datenum(1990,1+(0:mns)',1),'yyyymm'));
XXX = cell(size(a));
[~,~,XXX] = cellfun(@(x)xlsread(fullfile(yourpath,[x,'.xlsx']),'Sheet1','E3:E502'),a,'un',0);
  3 件のコメント
Andrei Bobrov
Andrei Bobrov 2012 年 7 月 17 日
please try this is code:
[Y M] = datevec(datenum({'199001';'199108'},'yyyymm'))
mns = diff([Y M])*[12;1]
a = cellstr(datestr(datenum(1990,1+(0:mns)',1),'yyyymm'))
Xiao Tang
Xiao Tang 2012 年 7 月 17 日
It's perfect! Thanks

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

その他の回答 (0 件)

カテゴリ

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