Asked by Behzad Navidi
on 4 Nov 2019

Hello,

I have a 3d array, precip= :,:, 8760. in fact 8760 rows are available in one column. I want to find the maximum value in this column 24-by-24 in rows. And saving the bigger value and eliminate the smaller one. and do it for all 8760-row

so if the dimension before doing this is precip = :, :, 8760, after this work should be precip = :, :, 365.

I wanna practical this for a 3d array which the third dimension is what I talking about.

I'm attaching all my array. as the volume of original file is so big I cut first 72 rows and attach it

Thank you

Answer by Shubham Gupta
on 14 Nov 2019 at 0:19

Edited by Shubham Gupta
on 14 Nov 2019 at 0:26

Accepted Answer

According to the comments, you have provided, this will produce the desired output :

yd = max(max(mn2t)); % first find maximum for each hour

y = reshape(yd,24,1,size(yd,3)/24); % reshape it by day

output = max(y); % find maximum of each day

Let me know if this works !

Behzad Navidi
on 14 Nov 2019 at 0:45

Dear Shubham,

It's works perfect for the array. thank you so much. I gonna accept your answer but webpage says: An Error Occurred (Unable to complete the action because of changes made to the page. Reload the page to see its updated state)

I have faced this error previously, and I know a few hours later it will be fixed and I can click on accept answer.

but now just in a case do you know how to use this code when mn2t is cell (34*1 cell) (instead of an array) and using this code for all 34 rows of this cell (the cell consists of 34 of this 3d array?

Thank you - I will accept your answer.

Shubham Gupta
on 14 Nov 2019 at 1:28

Simply use for loop mn2t:

output = cell(size(mn2t));

for i = 1:length(mn2t)

mn2t_mat = mn2t{i}; % extract matrix of ith element

yd = max(max(mn2t_mat)); % first find maximum for each hour

y = reshape(yd,24,1,size(yd,3)/24); % reshape it by day

output{i} = max(y); % find maximum of each day

end

Output will be cell vector with each cell containing maximum of each cell of mn2t.

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 7 Comments

## Shubham Gupta (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/489065-how-to-find-the-maximum-value-for-each-24-rows-in-an-array#comment_763252

## Shubham Gupta (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/489065-how-to-find-the-maximum-value-for-each-24-rows-in-an-array#comment_763253

## Behzad Navidi (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/489065-how-to-find-the-maximum-value-for-each-24-rows-in-an-array#comment_763258

## Shubham Gupta (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/489065-how-to-find-the-maximum-value-for-each-24-rows-in-an-array#comment_763605

## Behzad Navidi (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/489065-how-to-find-the-maximum-value-for-each-24-rows-in-an-array#comment_767079

## Shubham Gupta (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/489065-how-to-find-the-maximum-value-for-each-24-rows-in-an-array#comment_767082

## Behzad Navidi (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/489065-how-to-find-the-maximum-value-for-each-24-rows-in-an-array#comment_767083

Sign in to comment.