Hello,
I have E matrix which is 24*3*4. I want to sum the maximum values that corresponding to a specify (n). lets say i want to sum different number of maximum values of each row. for example, the first row of E(1,1:3,1:4)=
ans(:,:,1) =
31 32 33
ans(:,:,2) =
21 22 23
ans(:,:,3) =
71 72 73
ans(:,:,4) =
51 52 53
now i want to sum the the two maximum values of 1 which are 33 , 32 and the maximum value of 2 which is 23 and two maximum values of 3 which are 73,72 and the three maximum values of 4 which are 51,52,53. So, the result should be a matrix which diminsion is (24*1*4) and look like
ans(:,:,1) =
65
ans(:,:,2) =
23
ans(:,:,3) =
145
ans(:,:,4) =
156
Any thought of how i can do that . Many thanks :)

2 Comments

I'd guess sort() and sum() would be involved. But make it easy for people to help you, not hard -- attach "E" in a .mat file
save('answers.mat', 'E');
Then attach answers.mat with the paper clip icon.
Tthank you. I have attached the matrices in .m file

Sign in to comment.

 Accepted Answer

Try this
m = [2 1 2 3];
out = zeros(size(EGSE_bat,1), 1, size(EGSE_bat,3));
for i = 1:size(EGSE_bat,3)
out(:,:,i) = sum(maxk(EGSE_bat(:,:,i), m(i), 2), 2);
end

2 Comments

Thank you, thats work
I am glad to be of help!

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!