Find maximum for each Image in table
Afficher commentaires plus anciens
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 commentaires
Walter Roberson
le 7 Juin 2021
findgroups() splitapply()
Pouyan Sadeghian
le 7 Juin 2021
Modifié(e) : Pouyan Sadeghian
le 7 Juin 2021
Réponse acceptée
Plus de réponses (2)
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 commentaires
Pouyan Sadeghian
le 7 Juin 2021
Walter Roberson
le 7 Juin 2021
You did not save the code for findmax. I posted it above -- it is directly below the results.
Pouyan Sadeghian
le 7 Juin 2021
Walter Roberson
le 7 Juin 2021
@Duncan Po's response is better than mine for this purpose !
Pouyan Sadeghian
le 7 Juin 2021
Sulaymon Eshkabilov
le 7 Juin 2021
A = ... % Table of all data
B = A.MaxPosition; % Separate out the column
1 commentaire
Pouyan Sadeghian
le 7 Juin 2021
Catégories
En savoir plus sur Mathematics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
