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

1 visualizzazione (ultimi 30 giorni)
Cladio Andrea il 28 Feb 2015
Modificato: Guillaume il 28 Feb 2015
Hello guys, i have one big problem lets say i have code:
AA = 1:1:3600000
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 CommentiMostra NessunoNascondi Nessuno
Guillaume il 28 Feb 2015
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 il 28 Feb 2015
Modificato: Guillaume il 28 Feb 2015
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.

Accedi per commentare.

Categorie

Scopri di più su Matrix Indexing in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by