Calculate mean of matrix for specific interval

조회 수: 6 (최근 30일)
Pelle Adema
Pelle Adema 2021년 9월 2일
댓글: Pelle Adema 2021년 9월 2일
Hi all,
I have elevation data stored in a 121x721 matrix called DEM.
I want to calculate 2 things:
1) the cross-sectionally averaged mean elevation along the flume. i.e. the mean elevation per column of matrix DEM. (This works OK)
2) The cross-sectionally averaged mean elevation along the flume for DEM(11:110). So without the edges. (Does not work yet)
My code works for the first but not for the second thing I try to calculate.
See the minimal working example below to see the code I used.
What I need is a 1x721 array of the mean value of columns in DEM between 11 and 110.
Hope this makes sense and someone can point me in the right direction.
Thanks
%% MWE
% DEM contains a digital elevation model (elevation data).
DEM = rand(121,721);
% calcultate DEM means for full DEM
DEM_mean = mean(DEM); % this returns a 1x721 array which is what I need
% calculate DEM means for specific interval of DEM
DEM_mean2 = mean(DEM,11:110); % this returns a 121x721 matrix, but I need a 1x721 array like above.

채택된 답변

Konrad
Konrad 2021년 9월 2일
Hi Pelle,
you need to index your variable DEM correctly:
DEM_mean2 = mean(DEM(11:110,:));
Best, Konrad
  댓글 수: 1
Pelle Adema
Pelle Adema 2021년 9월 2일
Hi Konrad,
Thanks for your answer. This was indeed the problem and your solution gives me what I need.
Best,
Pelle

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by