Find maximum for each Image in table
1 次查看(过去 30 天)
显示 更早的评论
Good evening,
I have a similar issue like my previous question (For Loop Table Matlab - MATLAB Answers - MATLAB Central (mathworks.com)).
I have a small excerpt of my table. In the coloumn Label you see my Images and in the column MaxPosition and Intenisty my measurements.
Number Label MaxPosition Intensity
______ __________________________ ___________ ________
1 {'Image0100 16-28-31.bmp'} 94 10
2 {'Image0100 16-28-31.bmp'} 123 8
3 {'Image0101 16-28-46.bmp'} 95 23
4 {'Image0101 16-28-46.bmp'} 124 43
5 {'Image0102 16-29-01.bmp'} 95 22
6 {'Image0102 16-29-01.bmp'} 125 54
7 {'Image0103 16-29-16.bmp'} 96 94
8 {'Image0103 16-29-16.bmp'} 126 30
9 {'Image0104 16-29-31.bmp'} 98 49
10 {'Image0104 16-29-31.bmp'} 127 39
11 {'Image0105 16-29-46.bmp'} 98 20
12 {'Image0105 16-29-46.bmp'} 128 10
13 {'Image0106 16-30-01.bmp'} 98 2
14 {'Image0106 16-30-01.bmp'} 128 94
15 {'Image0107 16-30-16.bmp'} 99 93
16 {'Image0107 16-30-16.bmp'} 129 54
17 {'Image0108 16-30-31.bmp'} 100 32
18 {'Image0108 16-30-31.bmp'} 130 44
Now I want to find the max of the Intensity for every Image with the corresponding MaxPosition.
I use varfun but this command gives me the max of the MaxPosition and the max of the Intensity of every Image, not the corresponding one.
For example for Image0100 the max Intensity is 10 and the correpsonding to it is 94. And I want to display 94 in my new table.
Thanks.
Best
Pouyan
2 个评论
采纳的回答
Duncan Po
2021-6-7
You can use groupsummary to find the maximum value of each group:
T1 = groupsummary(T, 'MaxPosition', 'max', 'Intensity');
更多回答(2 个)
Walter Roberson
2021-6-7
data = {
1 {'Image0100 16-28-31.bmp'} 94 10
2 {'Image0100 16-28-31.bmp'} 123 8
3 {'Image0101 16-28-46.bmp'} 95 23
4 {'Image0101 16-28-46.bmp'} 124 43
5 {'Image0102 16-29-01.bmp'} 95 22
6 {'Image0102 16-29-01.bmp'} 125 54
7 {'Image0103 16-29-16.bmp'} 96 94
8 {'Image0103 16-29-16.bmp'} 126 30
9 {'Image0104 16-29-31.bmp'} 98 49
10 {'Image0104 16-29-31.bmp'} 127 39
11 {'Image0105 16-29-46.bmp'} 98 20
12 {'Image0105 16-29-46.bmp'} 128 10
13 {'Image0106 16-30-01.bmp'} 98 2
14 {'Image0106 16-30-01.bmp'} 128 94
15 {'Image0107 16-30-16.bmp'} 99 93
16 {'Image0107 16-30-16.bmp'} 129 54
17 {'Image0108 16-30-31.bmp'} 100 32
18 {'Image0108 16-30-31.bmp'} 130 44};
T = cell2table(data, 'VariableNames', {'Number', 'Label', 'MaxPosition', 'Intensity'});
T(1:5,:)
[G, ID] = findgroups(T.Label);
results = cell2mat(splitapply(@findmax, T.MaxPosition, T.Intensity, G));
output = table(ID, results(:,1), results(:,2), 'VariableNames', {'Label', 'Intensity', 'MaxPosition'});
output
function results = findmax(Pos, Inten)
[maxinten, idx] = max(Inten);
results = {maxinten, Pos(idx)};
end
5 个评论
Sulaymon Eshkabilov
2021-6-7
A = ... % Table of all data
B = A.MaxPosition; % Separate out the column
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!