필터 지우기
필터 지우기

How to find the elements that is repeating and also how many times it repeated?

조회 수: 1 (최근 30일)
Cladio Andrea
Cladio Andrea 2015년 2월 28일
편집: Guillaume 2015년 2월 28일
Hello guys, i have one big problem lets say i have code:
AA = 1:1:3600000
XX = dasadim1;
YY(:,1) = AA;
YY(end,2) = 0;
YY(end,3) = 0;
YY(end,4) = 0;
ind1 = find(ismember(AA,XX(:,1)));
YY(ind1,2) = AA(ind1);
YY(:,3) = histc(XX(:,1),AA);
XX(:,1) shows the corresponding numbers lets say, 1700000,1900000,, where data is generated with YY(:,3) i found check XX and YY and if match then insert 1 for YY(:,3) but lets say i have two same elements in XX(:,1) 1400000 and 14000000 if i run the code i got error because in YY(:,3) element it has to be 2 instead 1,can you help me please?
  댓글 수: 2
Guillaume
Guillaume 2015년 2월 28일
It's a strange way of constructing YY. This would be simpler and clearer:
YY = [AA' zeros(numel(AA), 3)];
Secondly,
ind = find(logicalarray)
A(ind) = B(ind)
can be replaced simply by
A(logicalarray) = B(logicalarray)
that is you don't need to waste time with the find.
Guillaume
Guillaume 2015년 2월 28일
편집: Guillaume 2015년 2월 28일
Your code works fine for me even when there are repetitions in XX. It also seems to be doing what you're asking in the title of your question, so it's unclear what your problem is.
Maybe give an example with some inputs and expected result, if your code doesn't do what you want.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by