필터 지우기
필터 지우기

How to find the maximum value for each 24 rows in an array?

조회 수: 5 (최근 30일)
BN
BN 2019년 11월 4일
답변: BN 2019년 11월 14일
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
Shubham Gupta
Shubham Gupta 2019년 11월 13일
편집: Shubham Gupta 2019년 11월 13일
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
BN 2019년 11월 13일
ok if assume that on this earth 1 day is of 2hr, then the output is:
Day = 1
T = 90
Day = 2
T = 900
I don't want to change the first and second dimensions.
input = :, :, 87600
output = :, :, 365 or 366

댓글을 달려면 로그인하십시오.

채택된 답변

Shubham Gupta
Shubham Gupta 2019년 11월 14일
편집: Shubham Gupta 2019년 11월 14일
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 !
  댓글 수: 2
BN
BN 2019년 11월 14일
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
Shubham Gupta 2019년 11월 14일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

BN
BN 2019년 11월 14일
Thank you ?

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by