identifying successive dates in a cell vector

Dear all
I have the following sequence of dates
A={
'11/08'
'11/08'
'12/08'
'01/09'
'02/09'
'03/09'
'04/09'
'05/09'
'06/09'
'07/09'
'08/09'
'09/09'
'10/09'
'11/09'
'11/09'
'12/09'
'01/10'
'02/10'
}
As you can see some succesive dates contain the same month/year (for example the first 2 dates).
I would like to be able to identify the identical succesive dates
so as to construct an if statetement that will say
for ii=2:length(A)
if A(ii,1)==A(ii-1,1)
'do this'
end
end

 採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 8 月 1 日
編集済み: Andrei Bobrov 2012 年 8 月 1 日

0 投票

[a,b,c] = unique(A);
[jj,jj] = sort(b);
out = accumarray(c,(1:numel(c))',[],@(x){x});
out = [a(jj),out(jj)];
ADD
a = [false all(diff(char(A)-'0')==0,2)'];
a(strfind(a,[0 1])) = true;
or
[c,c,c] = unique(A);
k = [false;diff(c)==0];
k(find(k)-1)=true;

4 件のコメント

Sabbas
Sabbas 2012 年 8 月 1 日
thanks andrei. But I need to leave the initial vector of dates unchanged so as to have for example
AA=(1, 1,0, 0,..)
Sabbas
Sabbas 2012 年 8 月 1 日
could you please help me?. I am so close in finding the correct answer
thanks
Andrei Bobrov
Andrei Bobrov 2012 年 8 月 1 日
see ADD
Sabbas
Sabbas 2012 年 8 月 1 日
Excellent!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および 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