How to find the maximum value for each 24 rows in an array?
Show older comments
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
7 Comments
Shubham Gupta
on 4 Nov 2019
Edited: Shubham Gupta
on 4 Nov 2019
Above mentioned precip= :,:, 8760 is not a correct way to show the dimesions of a 3D array. If precip is a 3D array of ( r x c x p ) dimension, we need to know r, c & p where 'r' is rows 'c' is columns and 'p' is pages. Also, dimesion of the final output.
Now, my understanding is precip is of dimension (24 x 1 x 365 )? If so,
result = max(precip)
might be the necessary output of dimension (1 x 1 x 365) where each page contains the maximum of each input page. Let us know more details about precip. Cheers
Shubham Gupta
on 4 Nov 2019
Though for you attached data which is of dimension (1 x 1 x 72), if this a data for first 3 days. You want to convert it to a 3d array of dimension (24 x 1 x 3) where each page represents a day. You can do by
y = reshape(mn2t_first_24hours,24,1,length(mn2t_first_24hours)/24);
Then to find max of each day
output = max(y)
will give you output of dimesion (1x1x3) where each page will represent maximum value of each day. If that's what you want?
Shubham Gupta
on 4 Nov 2019
Edited: Shubham Gupta
on 4 Nov 2019
As I have mentioned in the comments, this code will only work for dimension of (1x1x8760) but seems like your "mn2t" array is of (49x41x8760) dimension which has 49 rows, 41 columns & 8760 pages. Can you please explain, what does these dimesions represent for your data? and along which dimension you want the maximum value?
By the way, this maybe the thing you want but I may be completely wrong.
yd = max(max(mn2t)); % converts it into 1x1x8760 array where each page of 'yd' is the maximum of each page in 'mn2t'
y = reshape(yd,24,1,length(yd)/24); % reshape it to 24x1x365;
output = max(y);
If above is not what you want, let us know what is the output that you are expecting using a simple example?
About the error (why it ocurred):
you have mn2t with (49*41*8760 = 17598840 elements) and you are reshaping it to (24*1*365 = 8760 elements) which is not the same number of elements as previous one, and this is not permissible in MATLAB
BN
on 13 Nov 2019
Shubham Gupta
on 13 Nov 2019
Edited: Shubham Gupta
on 13 Nov 2019
Let's take a example with an array of dimension 2x3x4. So time = 1hr, 2hr, 3hr & 4hr. At each hour let's assume random data for temp & assume that on this earth 1 day is of 2hr.
t = 1hr
T = [20 30 40
50 60 70];
t = 2hr
T = [30 50 70
80 90 75];
t = 3hr
T = [-20 40 10
15 900 80];
t = 4hr
T = [25 55 11
10 -45 9];
What is the output that you are expecting in this hypothetical situation? I understand your 3rd dimesion (pages) will be 2 but I still don't know what do you want to do with the 1st & 2nd dimesion. I am expecting your output to be:
Day = 1
T = ??
Day = 2
T = ??
BN
on 13 Nov 2019
Accepted Answer
More Answers (1)
BN
on 14 Nov 2019
0 votes
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!