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)
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!

Réponse acceptée

Jos (10584)
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)

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!

Translated by