best way to search date in vector

1 回表示 (過去 30 日間)
Alina
Alina 2011 年 6 月 29 日
hello,
i have a vector of numerical dates that repeat but not in a specific order. i need to search for all dec 1984 then do some things then search for all dec 1985 and do some things and so on until dec 2010. what is the easiest way to do it? i tried converting to string date and then concatenate but it takes too long. any suggestion on what is the best way?
many thanks, a

採用された回答

Andrei Bobrov
Andrei Bobrov 2011 年 6 月 29 日
dev = datevec(dateinput);
dateout = sortrows(dev(dev(:,2)==12,1:3),1)

その他の回答 (2 件)

Jan
Jan 2011 年 6 月 29 日
date_numbers = [733588.513, 733688.513, 733788.513];
date_vector = datevec(date_numbers);
for year = 1984:2010
index = and(date_vector(:, 1) == i, date_vector(:, 2) == 12);
% Now "index" is the LOGICAL index, which is
% very efficient usually for selecting data.
% Perhaps "find(index)" is useful also.
end

Krishna Kumar
Krishna Kumar 2011 年 6 月 29 日
With the description you've given, seems 'find' will do it fine- x=find(vector==1984). Seems you want to do sth like a loop- for ind=1984:2010 x=find(vector==ind); %%Your statements%% end
  1 件のコメント
Alina
Alina 2011 年 6 月 29 日
thanks but the problem is the stings is saved as a nx11 matrix (basically one cell for each character in 30-Dec-1984). if i try to concatenate this it takes too long, as n is large.

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

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by