How can I find the last element amongst a set of grouping variables?

2 views (last 30 days)
I have a 150x2 matrix in which the first column contains numbers that can be considered 'grouping variables' and the second column contains values associated with those grouping variables. So a small 12x2 version would look like this
200741 5441
200741 5524
200741 5428
200742 5670
200742 5668
200742 5559
200742 5215
200743 5184
200743 5473
200743 5496
200743 5568
200743 5702
I'd like to find the last value of the values associated with each grouping variable. So the above example would yield a last element of 5428(for variable 200741), last element of 5215(for variable 200742) & last element of 5702(for grouping variable 200743). After I find the unique vales of grouping variables in coumn1, how do I take the last element in column2 corresponding to each grouping variable?

Answers (1)

dpb
dpb on 11 Feb 2015
ix=[find(diff(x(:,1));length(x)]; % index of breakpoints plus last
subset=x(ix,:); % the selected points

Community Treasure Hunt

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

Start Hunting!