MATLAB: Calc of mean and standard deviation

MATLABmeanplotstd

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.

Best Answer

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
Related Question