MATLAB Answers

Calc of mean and standard deviation

27 ビュー (過去 30 日間)
Kofial
Kofial 2020 年 1 月 23 日 16:12
コメント済み: Image Analyst 2020 年 1 月 24 日 2:23
Hi. I have
A = [1,-1,0,6,8,9]
B = [1,-2,0,-6,8,9]
C = [-2,-1,0,6,8,9]
How can I calc the mean of three of them (excluding NaN) std and plot them in one graph?
The result should look like the photo. Maybe this is elementary question but I'm still learning. Thanks.

  0 件のコメント

サインイン to comment.

採用された回答

Image Analyst
Image Analyst 2020 年 1 月 23 日 20:09
Is this what you want:
A = [1,-1,0,6,8,9]
B = [1,-2,0,-6,8,9]
C = [-2,-1,0,6,8,9]
% Compute mean and std dev.
meanVec = mean([A; B; C], 'omitnan')
stdVec = std([A; B; C], 'omitnan')
% Plot everything
plot(A, 'r.-', 'LineWidth', 2, 'MarkerSize', 10);
hold on;
plot(B, 'g.-', 'LineWidth', 2, 'MarkerSize', 10);
plot(C, 'b.-', 'LineWidth', 2, 'MarkerSize', 10);
plot(meanVec, 'k.-', 'LineWidth', 2, 'MarkerSize', 10);
grid on;
legend('A', 'B', 'C', 'Mean', 'Location', 'northwest');
0000 Screenshot.png

  2 件のコメント

Kofial
Kofial 2020 年 1 月 23 日 20:34
Yesss. Only with adding std in the plot as well. Thank you!
Image Analyst
Image Analyst 2020 年 1 月 24 日 2:23
It's trivial to add it, and I expect you have already.
A = [1,-1,0,6,8,9]
B = [1,-2,0,-6,8,9]
C = [-2,-1,0,6,8,9]
% Compute mean and std dev.
meanVec = mean([A; B; C], 'omitnan')
stdVec = std([A; B; C], 'omitnan')
% Plot everything
plot(A, 'r.-', 'LineWidth', 2, 'MarkerSize', 10);
hold on;
plot(B, 'g.-', 'LineWidth', 2, 'MarkerSize', 10);
plot(C, 'b.-', 'LineWidth', 2, 'MarkerSize', 10);
plot(meanVec, 'k.-', 'LineWidth', 2, 'MarkerSize', 10);
plot(stdVec, 'm.-', 'LineWidth', 2, 'MarkerSize', 10);
grid on;
legend('A', 'B', 'C', 'Mean', 'Standard Deviation', 'Location', 'northwest');
0000 Screenshot.png

サインイン to comment.

その他の回答 (1 件)

John D'Errico
John D'Errico 2020 年 1 月 23 日 16:19
編集済み: John D'Errico 2020 年 1 月 23 日 16:20
It should look like what photo? The mind reading toolbox has never gotten past beta testing state, and the copy I have is full of bugs.
Hint: create ONE matrix, that is 3x6. Now can you use the functions mean and std on the matrix?
This points out the flaw in creating multiple variables, when one array will suffice.

  3 件のコメント

Kofial
Kofial 2020 年 1 月 23 日 16:55
I think the matrix could be helpful. I need to plot the three of them in one graph. Mean,STD,and A,B,C versus any timeframe (10:00-12:00 for example).
John D'Errico
John D'Errico 2020 年 1 月 23 日 19:05
Please stop answering with something that is purely a comment. You never even attached a picture to your answer. You clearly know how to make a comment, since you made one. And you can attach a picture to a comment.
But if you even admit a matrix would be helpful, then TRY IT!!!!!!! Make some effort.
Kofial
Kofial 2020 年 1 月 23 日 19:09
You don't have to be mean!!! Organizing in a matrix it's only the first step and doesn't help much for the total result. I can't visualize how to plot them. That's the most important.

サインイン to comment.

サインイン してこの質問に回答します。

タグ

製品


リリース

R2019a

Translated by