detect consecutive duplicates in a structure

조회 수: 16 (최근 30일)
Julien Bouchez
Julien Bouchez 2014년 5월 27일
답변: Andrei Bobrov 2014년 5월 27일
Hi all
I am trying to detect consecutive duplicates in a structure like this
A(1).a=1
A(2).a=1
A(3).a=3
A(1).b=true
A(2).b=true
A(3).b=false
A has many .a .b ...
I did a for loop with this test :
ttest=A(ii)==A(ii-1)
But I get the error
Undefined function 'eq' for input arguments of type 'struct'.
So I described every .a .b ... individually
all([A(ii).a == A(ii-1).a,A(ii).b == A(ii-1).b,...])
which is a pain and lakes evolutivity
How would you do that ?
Regards
Julien

답변 (2개)

George Papazafeiropoulos
George Papazafeiropoulos 2014년 5월 27일
A(1).a=1
A(2).a=1
A(3).a=3
A(1).b=true
A(2).b=true
A(3).b=false
for ii=2:3
ttest(ii-1)=A(ii).a==A(ii-1).a
end
for ii=2:3
ttest(ii-1)=A(ii).b==A(ii-1).b
end

Andrei Bobrov
Andrei Bobrov 2014년 5월 27일
H = squeeze(struct2cell(A));
[~,~,c] = unique(reshape([H{:}],size(H)));
ttest = histc(c,unique(c));

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by