How to plot the mean and standard deviation of collected data
Show older comments
Hi!
I've been trying to use raacampbell's shadedErroBar (attached) to plot some data that I've collected. I have three different data files that I import (load and extension data), and then I was trying to find the mean and standard deviation. I'm trying to generate a graph that looks like the following:

I've attached my code, the shadedErroBar code, and some of the data files that I've been using. The current code throws the error:
Error using sum
Invalid data type. First argument must be numeric or logical.
Error in mean (line 127)
y = sum(x, dim, flag) ./ mysize(x,dim);
Error in materials_curve (line 40)
m_load = mean(l);
Sorry if this is a really introductory question, I'm just really rusty on my data processing/plotting skills. Thank you so much! The code is also below:
clear all; close all; clc;
colors = 1/255*[158,1,66 ; 213,62,79; 244,109,67; 253,174,97; ...
254,224,139; 255,255,191; 230,245,152; 171,221,164; 102,194,165; 50,136,189; 94,79,162 ];
files = dir('med*.csv');
n = length(files);
figure(1); clf;
l = [];
e = [];
for i = 1:n
data = readtable(files(i).name);
load = data(5:2400,3);
ext = data(5:2400,2);
ltable = table2array(load);
etable = table2array(ext);
l = [l ltable];
e = [e etable];
end
m_load = mean(l);
m_ext = mean(e);
std_1 = std(l);
max_load = mean(max(l));
A = max(l);
std_2 = std(A);
ph = shadedErrorBar(m_ext, m_load, std_1);
set(ph.mainLine, 'LineWidth', 1, 'Color', colors(1,:)) % modify the mean line
set(ph.edge, 'linewidth', 0.5, 'color', [colors(1,:) 0.1]) % modify edge lines (+/-) 1 std dev lines
set(ph.patch, 'facecolor', colors(1,:), 'facealpha', 0.5) % modify shaded region
xlabel('Extension')
ylabel('Load (kN)')
Accepted Answer
More Answers (0)
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!