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

조회 수: 1 (최근 30일)
Hello everyone,
I have a 3d array, precip= :,:, 720. in fact 720 is a column. I want to find the maximum value in this column two-by-two in rows. And saving the bigger value and eliminate the smaller one. and do it for all 720-row two-by-two
for example:
1) 54
1) 34
2) 97
2) 21
3) 3
3) 0
to
1) 54 ( 54>34)
2) 97
3) 3
so if the dimension before doing this is precip = :, :, 730, 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.
Thank you

채택된 답변

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2019년 11월 3일
편집: Thiago Henrique Gomes Lobato 2019년 11월 3일
If I understood right you want the maximum element-wise matrix entry between the two matrices that appear in your 3rd dimension in consecutive index, right? If it is this I belive this is the fastest way to do it in Matlab
A = load('my_array.mat');
A = A.the_array;
% Create Array to store the data
NewArray = max(A(:,:,1:2:end),A(:,:,2:2:end)); % Save maximum element-wise element for each matrix between 2 by 2 indexes
size(NewArray)
ans =
25 21 365

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by