How to average first two dimension of 3D array/matrix?
27 views (last 30 days)
I am calculating the average of first two dimension of a 3D matrix but it is showing following error:
Error using sum
Dimension argument must be a positive integer scalar within indexing range.
Error in mean (line 116)
y = sum(x, dim, flag) ./ size(x,dim);
Also, I have used a simplest example given in topic 'Mean of Array Page' in https://in.mathworks.com/help/matlab/ref/mean.html but I am getting same error.
I am using MATLAB 2018a
Thanks in advance
More Answers (2)
Wan Ji on 1 Sep 2021
Edited: Wan Ji on 1 Sep 2021
Just use mean function to average first two dimension of 3D matrix
a = rand(2,3,4); % I just use rand function so the result is randomly displayed
b = mean(a,1:2) % 1:2 means the first two dimension
The result is
b = mean(a,1:2)
If you want to get array of b
b = squeeze(b) % or b = b(:);