I would like to get an example of the difference between the maximum and minimum values by grouping grpstats or looping statements

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!

 채택된 답변

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2019년 2월 4일

댓글:

2019년 2월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by