MATLAB: Average of array element at defined interval average of element of array Suppose, a=[1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5] i want to calculate average of group of five nos. so that my resulting array is like avg=[3 3 3 3] Can any one help me for the same. Best Answer Use the rehaspe function, then mean, since it takes the means of columns as its default behaviour:a=[1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5];ar = reshape(a, [], 4)ar_mean = mean(ar)produces:ar = 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5ar_mean = 3 3 3 3 Related SolutionsMATLAB: How to find the indices of same values within a vector and bin them together The following statement will return the list of all the averages according to the way you mentioned in your question.meanVector = splitapply(@(x) mean(x), B', A')since A have 5 unique elements, meanVector will also contain 5 elements corresponding to the mean value from B. MATLAB: How to find unique pages in a 3d matrix A = cat(3, [1 2; 3 4;0 0], [5 6; 3 4; 0 0], [5 6; 1 2;0 0],[1 2; 3 4;0 0])[n,m,p]=size(A)a=reshape(A,n,[],1)b=reshape(a(:),n*m,[])'c=unique(b,'rows','stable')'reshape(c,n,m,[]) Related QuestionRemove redundancy values from matrixEnter two numbers to generate a regular sequenceFinding average between TFunct1,TFunct2,TFunct3Conditional mean for a matrix (calculate the mean ignoring the negative numbers)How to combining repeating groups of elements of an array while preserving order
Best Answer