# How do I plot mean value of many vectors?

20 views (last 30 days)

Show older comments

Hi, how do I plot mean value of many vectors if the vectors is:

A = [0.081291416701925745, 0.14122419702054573, 0.27766822860596385, 0.380279607387342, 0.54696467005974858, 0.62106188150998232]

B = [0.09500440211107572, 0.20768728979483142, 0.28754282325812419, 0.39277042574339854, 0.50507788272174581 0.58958996553175536]

C = [0.15915833966016121, 0.167108268948393, 0.27719960333431254, 0.40183364422854823, 0.47372736284207673, 0.62400570035234515] ... and so on.

Thanks!

##### 1 Comment

Jan
on 15 May 2015

### Answers (2)

Jan
on 15 May 2015

If the core of the question is how a list of variables can be processed, the answer is:

Don't do this. Do not store a bunch of variables with different names, but store the data in an array. If all vectors have the same length, a matrix is efficient, otherwise a cell array:

M = [0.081291416701925745, 0.14122419702054573, 0.27766822860596385, ...

0.380279607387342, 0.54696467005974858, 0.62106188150998232; ...

0.09500440211107572, 0.20768728979483142, 0.28754282325812419, ...

0.39277042574339854, 0.50507788272174581 0.58958996553175536; ...

0.15915833966016121, 0.167108268948393, 0.27719960333431254, ...

0.40183364422854823, 0.47372736284207673, 0.62400570035234515];

Then you can calculate the mean directly:

MeanM = mean(M, 2);

With a cell:

A{1} = [0.081291416701925745, 0.14122419702054573, 0.27766822860596385, ...

0.380279607387342, 0.54696467005974858, 0.62106188150998232];

A{2} = [0.09500440211107572, 0.20768728979483142, 0.28754282325812419, ...

0.39277042574339854, 0.50507788272174581 0.58958996553175536];

A{3} = [0.15915833966016121, 0.167108268948393, 0.27719960333431254, ...

0.40183364422854823, 0.47372736284207673, 0.62400570035234515];

MeanA = cell(size(A));

for k = 1:numel(A)

MeanA{k} = mean(A{k});

end

##### 0 Comments

Mahdiyar
on 15 May 2015

Hi The question is not complete because the mentioned vectors are a one row matrix and the average of this matrix is a number. So why you want to plot a point??

If you want to find the average value of some row matrices , you can do the following code. Note that in this case the matrices should be the same size, otherwise you have to calculate the average value of each of them separately.

Average = mean(transpose([A; B; C]));

##### 1 Comment

Jan
on 15 May 2015

Instead of transposing you can tell mean() the dimension to operate on:

mean([A; B; C], 2)

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!