selecting columns with certain time period and placing in new array

2 ビュー (過去 30 日間)
Sophie Stringer
Sophie Stringer 2019 年 8 月 19 日
コメント済み: Bob Thompson 2019 年 8 月 20 日
Hi there,
I have a data file ranging from 1974 to 2019 and I would like to select the data that corresponds to the period 2003/01/01 to 2009/12/31 and create another array (not sure if thats the right term).
Currently column 1,2 & 3 indicate year, month and day. But preferably would want to put this into a datenum() and create a serial date number.
If anyone has any idea how to this, any help would be greatly appreciated. I've attached the matlab file.
Kind regards,
Sophie

回答 (1 件)

Bob Thompson
Bob Thompson 2019 年 8 月 19 日
In general, I would make an effort to extract the data using logic indexing. You can certainly convert the mdy into a datetime variable, but if you're looking to sort by each year it is not necessary.
I have not looked at your attached file (it's a limitation on my end), so the specific designations are probably off in the example. Adjust as needed.
data = mjo_data(mjo_data(:,1)==[2003:2009],:);
time = datetime(data(:,1:3))
  2 件のコメント
Sophie Stringer
Sophie Stringer 2019 年 8 月 20 日
編集済み: Sophie Stringer 2019 年 8 月 20 日
Hi Bob,
Thanks for the help! I struggled to do it that way, I'm not entirley sure why, but kept getting an error message. I ended up doing it like this:
fname = 'Documents/Project/wh_index_clean2.txt';
MJO_data = load(fname);
% Select for data within 2003-2009
MJO_2003_09 = MJO_data(MJO_data(:,1)>=2003 & MJO_data(:,1)<=2009, :);
Bob Thompson
Bob Thompson 2019 年 8 月 20 日
The error was likely because it was trying to find elements which matched the entire array, which is a logic error on my part. Your alternative solution would be correct.

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

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by