I would like to get an example of the difference between the maximum and minimum values by grouping grpstats or looping statements
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
zheng linglin
le 4 Fév 2019
Commenté : zheng linglin
le 4 Fév 2019
Hello! I have a large Matlab dataset, the dataset formats are as following example:
id1 id2 value
148 168 80
148 168 82
148 168 96
568 566 66
568 566 28
568 566 88
568 566 62
166 688 88
166 688 82
......
Now I want each set of the same (id1,id2) will get a corresponding difference between the maximum value and the minimum value, for example:
id1 id2 diff
148 168 16
568 566 60
166 688 6
......
How can I get the results like this by using grpstats or looping statements? Thanks!
0 commentaires
Réponse acceptée
Jos (10584)
le 4 Fév 2019
Let M be your N-by-3 table, with columns [id1 id2 value] :
[out, ~, gi] = unique(M(:,[1 2]), 'rows')
out(:,3) = grpstats(M(:,3), gi, 'range')
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements 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!