How to find the elements that is repeating and also how many times it repeated?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Guillaume
le 28 Fév 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
le 28 Fév 2015
Modifié(e) : Guillaume
le 28 Fév 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.
Réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!