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

3 次查看(过去 30 天)
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?

回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by