How do I plot mean value of many vectors?
조회 수: 9 (최근 30일)
이전 댓글 표시
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
Jan
2015년 5월 15일
This is not "a vector", but "three vectors". So what does "and so on" mean exactly? This detail matters and we cannot guess it.
답변 (2개)
Jan
2015년 5월 15일
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
Mahdiyar
2015년 5월 15일
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
Jan
2015년 5월 15일
Instead of transposing you can tell mean() the dimension to operate on:
mean([A; B; C], 2)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!