How to find multiple duplicates in an array

6 vues (au cours des 30 derniers jours)
Amanda
Amanda le 11 Juil 2013
Hi, i am a beginner in matlab and trying to write a code for my data, but got stuck in this bit. I have a list of names in one vector(varies in length on each loaded data set) and time in another. In this list of names that corresponds to the time, there are at least 9 duplicates of each name, that i want to find and group together into bins and refer to the correct timing.
Example: n = [a b c d e a a e c d a ...]
t = [10.01 2.1 5.01 6.07 9.3 10.02 10.0 9 5.05 6.1 10.001 ...]
how can i ask matlab (7.6) to group all the a together and their t values, then all the b, all the c, and etc.
Much appreciated for any help.
  1 commentaire
Jan
Jan le 11 Juil 2013
Modifié(e) : Jan le 11 Juil 2013
Is n a cell string? Then this would be better:
n = {'a', 'b', 'c', ...}
What exactly does "group together into bins" mean and what is "the correct timing"? Perhaps it helps, if you post the wanted result for the shown example inputs.

Connectez-vous pour commenter.

Réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 11 Juil 2013
n = {'a' 'b' 'c' 'd' 'e' 'a' 'a' 'e' 'c' 'd' 'a'}
t = [10.01 2.1 5.01 6.07 9.3 10.02 10.0 9 5.05 6.1 10.001 ]
k=unique(n)
out=[k' cellfun(@(x) t(ismember(n,x)),k,'un',0)']

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by