Find maximum for each Image in table

2 次查看(过去 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 个评论
Pouyan Sadeghian
Pouyan Sadeghian 2021-6-7
编辑:Pouyan Sadeghian 2021-6-7
thank you for your response. I tried to understand these commands and tried to use them but I think it does not solve my problem.
Maybe my question is not clear.
l have for every image multiple measurements for Intensity and for MaxPosition. What I need is the maximum value of the Intensity for each image with the corresponding MaxPosition value to the Intensity.
I think what I get with your commands is the maximum value of Intensity and the maximum value of MaxPosition for each image. But I do not need this.
Or maybe I use these commanda false.
I hope you could understand my question better.
Best

请先登录,再进行评论。

采纳的回答

Duncan Po
Duncan Po 2021-6-7
You can use groupsummary to find the maximum value of each group:
T1 = groupsummary(T, 'MaxPosition', 'max', 'Intensity');
  2 个评论
Pouyan Sadeghian
Pouyan Sadeghian 2021-6-7
Thanks @Duncan Po for your response.
Its a very easy and quick command.
I was searching about a command like this. I used varfun but it did not solve my problem.
Best
Pouyan

请先登录,再进行评论。

更多回答(2 个)

Walter Roberson
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,:)
ans = 5×4 table
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
[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
output = 9×3 table
Label Intensity MaxPosition __________________________ _________ ___________ {'Image0100 16-28-31.bmp'} 10 94 {'Image0101 16-28-46.bmp'} 43 124 {'Image0102 16-29-01.bmp'} 54 125 {'Image0103 16-29-16.bmp'} 94 96 {'Image0104 16-29-31.bmp'} 49 98 {'Image0105 16-29-46.bmp'} 20 98 {'Image0106 16-30-01.bmp'} 94 128 {'Image0107 16-30-16.bmp'} 93 99 {'Image0108 16-30-31.bmp'} 44 130
function results = findmax(Pos, Inten)
[maxinten, idx] = max(Inten);
results = {maxinten, Pos(idx)};
end
  5 个评论
Walter Roberson
Walter Roberson 2021-6-7
@Duncan Po's response is better than mine for this purpose !
Pouyan Sadeghian
Pouyan Sadeghian 2021-6-7
alright.
I used your code and It satifies my problem but youre right. His response is shorter and easier.
Thank you

请先登录,再进行评论。


Sulaymon Eshkabilov
A = ... % Table of all data
B = A.MaxPosition; % Separate out the column
  1 个评论
Pouyan Sadeghian
Pouyan Sadeghian 2021-6-7
thank you for your response. Maybe you dont understand my problem or I explain it not clearly.
I want to find the max value of the Intensity for each image with the corresponding MaxPosition.
For example the maximum Intensity for image0101 is 43 (line 4) and I want also the corresponding MaxPosition to the maximum Intensity which is 124.
Maybe this is more understandable.

请先登录,再进行评论。

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by