MATLAB Answers

## Using mean function to take average of 4 columns for every row of data

Asked by Kelly

### Kelly (view profile)

on 12 Jan 2013
Accepted Answer by Azzi Abdelmalek

### Azzi Abdelmalek (view profile)

I'm just starting to get familiar with Matlab's mean function, but I'm confused as to how I can use it to get an average of multiple columns and display the result for every row of data. Details are as follows:

I have a 5000x14 matrix of data

I would like to average columns 7-10 for each row WITHOUT the use of a for loop. This should result in a 5000x1 matrix.

Some guidance would be very much appreciated.

#### 0 Comments

Log in to comment.

## 1 Answer

### Azzi Abdelmalek (view profile)

Answer by Azzi Abdelmalek

### Azzi Abdelmalek (view profile)

on 12 Jan 2013
Edited by Azzi Abdelmalek

### Azzi Abdelmalek (view profile)

on 12 Jan 2013
Accepted Answer

```A=rand(5000,14)  % Example
a=A(:,7:10);
out=mean(a,2)
```

Kelly

### Kelly (view profile)

on 12 Jan 2013

Thank you!

Log in to comment.

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

### Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

### MATLAB Academy

New to MATLAB?

Learn MATLAB today!