How to plot the average and std shade of 4 different datasets?
Show older comments
Hello, I'm trying to wrap my ahead around this problem but I'm working with big datasets and I'm not too familiar with Matlab capabilities and functions.
I have 4 different datasets, with different (but similar) sizes, same starting and end points (x coordinate), but different values in the middle.
Let's say, something like this:
dataset1_x = [0,2,3,5,7,4,3,2]
dataset1_y = [30,40,50,66,55,45,40,30]
dataset2_x = [0,1,2,4,6,7,5,4,2]
dataset2_y = [30,42,48,57,59,60,55,45,32]
dataset3_x = [0,3,5,6,7,6,5,4,3,2]
dataset3_y = [30,35,40,45,50,55,64,50,40,35]
Also, as you can see from the example datasets, they represent a cycle, and I don't know if that's a problem. Actual graphic representation of my datasets below:

Instead of plotting each dataset, I would like to plot an average line, and add the standard deviation as a shade around it.
My first problem is the fact that the datasets are different. I thought about interpolating values, getting an approximated version of each dataset with the same size as the others, but I don't know how to do it consistently throughout each dataset.
My second problem would be how to plot it. But, if the first problem is solved, I think I could use this code:
x = 1 : 300;
curve1 = log(x);
curve2 = 2*log(x);
plot(x, curve1, 'r', 'LineWidth', 2);
hold on;
plot(x, curve2, 'b', 'LineWidth', 2);
x2 = [x, fliplr(x)];
inBetween = [curve1, fliplr(curve2)];
fill(x2, inBetween, 'g');
From this answer: https://www.mathworks.com/matlabcentral/answers/180829-shade-area-between-graphs#answer_169649
Using upper (average value + std) and lower (average value - std) limits for the 2 curves to be filled inbetween.
Right? Or that wouldn't work?
Any help would be massively appreciated
Accepted Answer
More Answers (0)
Categories
Find more on Timetables 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!

