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

1 回表示 (過去 30 日間)
BN
BN 2019 年 11 月 3 日
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 Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by