Calculate the mean of two dimensions in a 3D array

27 ビュー (過去 30 日間)
Mar
Mar 2018 年 5 月 4 日
コメント済み: Rohit shaw 2021 年 10 月 10 日
I have a 3D array and I want to calculate the mean of the first two dimensions along the 3rd dimension but I am getting the following error
"Assignment has more non-singleton rhs dimensions than non-singleton subscripts".
My code looks as follows
MeanMatrix = zeros(1,1,30);
ImageROI = data(50:55,100:105,:);
for i=1:30
MeanMatrix(:,:,i) = mean(ImageROI(:,:,i));
end

採用された回答

Guillaume
Guillaume 2018 年 5 月 4 日
編集済み: Guillaume 2018 年 5 月 4 日
mean on a 2D matrix (your imageROI(:, :, i)) will return a vector. You can't assign a vector to a scalar (which is what MeanMatrix(:, :, i) is since it has 1 row and 1 column).
In any case, the loop is completely unnecessary:
MeanMatrix = mean(mean(ImageROI, 1), 2);
  1 件のコメント
Rohit shaw
Rohit shaw 2021 年 10 月 10 日
Hello, could you kindly tell me what would the command be if I have to use this command across 86 timesteps. I have a 3d array of 720x360x86. These are temperature values for the world.

サインインしてコメントする。

その他の回答 (1 件)

KL
KL 2018 年 5 月 4 日
編集済み: KL 2018 年 5 月 4 日
If you want the mean of all rows in every page(3rd dimension)
mean(ImageROI,1)
for columns in every page
mean(ImageROI,2)
and mean of pages,
mean(ImageROI,3)
if you're looking to calculate the mean of all elements in a page, mean2 would be something
mean2(ImageROI(:,:,pageNo)) %with a loop
without a loop, probably with reshape,
mean(reshape(ImageROI,[],size(ImageROI,2),1))

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by