selecting the highest value

8 次查看(过去 30 天)
I have dataset of 5 columns
1 3 .5 .6 89
1 2 03 .6 98
1 8 .3 .3 90
2 3 .2 .5 87
2 87 02 1 89
;
;
;
;
10 12 01 .3 87
10 12 03 07 99
10 0.3 0.5 10 78
i want to select highest values in column 5 for erach unique value,i nees as
1 8 .3 .3 90
2 87 02 1 89
10 12 03 07 99
please help
  1 个评论
Jan
Jan 2011-11-9
What is the input format? The semicolons look confusing...
Which values should be unique? Isn't 98 the highest value in column 5 for the 1 in the first column?!

请先登录,再进行评论。

采纳的回答

David Young
David Young 2011-11-9
I don't understand why the first row of your result is not
1 2 03 .6 98
as 98 is bigger than 90. Assuming you've made a mistake, the following code works, though there may, as ever, be neater methods:
data = [1 3 .5 .6 89
1 2 03 .6 98
1 8 .3 .3 90
2 3 .2 .5 87
2 87 02 1 89
10 12 01 .3 87
10 12 03 07 99
10 0.3 0.5 10 78];
indexcol = 1;
valuecol = 5;
indexlist = data(:,indexcol);
indexes = unique(indexlist);
results = zeros(length(indexes), size(data,2));
for k = 1:length(indexes)
rows = find(indexlist == indexes(k));
[unused, maxsubsetrow] = max(data(rows, valuecol));
maxrow = rows(maxsubsetrow);
results(k, :) = data(maxrow, :);
end
disp(results);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Condensed Matter & Materials Physics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by