Calculate the mean of each half of a matrix - MATLAB Cody - MATLAB Central

Problem 55240. Calculate the mean of each half of a matrix

Difficulty:Rate
Given a matrix with an even number of columns, n, return a 1-by-2 row vector where the first element is the mean of all the elements in the first n/2 columns, and the second element is the mean of all the elements in the second n/2 columns.
For example
A 3-by-4 matrix. The first two columns are blue, the second two are orange. The mean of the 6 blue elements is calculated. The mean of the 6 orange elements is calculated. The result is a 2-element row vector containing these two means.
A = [3 4 4 3;
1 2 5 3;
1 1 4 5];
m = halfmeans(A)
m =
2 4
(2 = mean of [3,4,1,2,1,1], 4 = mean of [4,3,5,3,4,5])

Solution Stats

52.54% Correct | 47.46% Incorrect
Last Solution submitted on Mar 03, 2025

Problem Comments

Solution Comments

Show comments
Primes and Rough Numbers, Basic ideas
What is a rough number? What can they be used...
2
4

Problem Recent Solvers516

Suggested Problems

More from this Author22

Problem Tags

Community Treasure Hunt

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

Start Hunting!
Go to top of page