How can I find the last element amongst a set of grouping variables?
2 ビュー (過去 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?
0 件のコメント
回答 (1 件)
dpb
2015 年 2 月 11 日
ix=[find(diff(x(:,1));length(x)]; % index of breakpoints plus last
subset=x(ix,:); % the selected points
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!