Shade area between two curves and maintain central solid line in shaded area

2 vues (au cours des 30 derniers jours)
Hi MATLAB community
I am knew to programing in MATLAB and using it to assist in streamlining some graphing process's with data (I am a biomechanics)
I have written a script to plot outputs from the program I use (which initially exports to excel) and have placed it below. I am wondering how to go about writing script to shade the area between y1sdupper and y1sdlower in a transparent red, as well as shade the area between y2sdupper and y2sdlower with a transparent blue (these are the +/- 1sd of the mean) while still keeping the solid y1 and y2 line visible. Any assistance will be greatly appreciated.
fprintf('Please note: Excel file setup:\n')
fprintf('Column A = x1\n')
fprintf('Column B = y1\n')
fprintf('Column C = y1SD\n')
fprintf('Column D = y2\n')
fprintf('Column e = y2SD\n')
fprintf('please ensure the excel file is saved in your "Current Folder"\n\n')
fprintf('If you have already completed this, please wait the program will sart in 5 seconds:\n\n')
pause(5)
fprintf('BLASTOFF')
pause (1)
prompt = {'Enter file name:'};
dlg_title = 'Input';
num_lines = 1;
defaultans = {'Book1'};
a = inputdlg(prompt,dlg_title,num_lines,defaultans);
file = strjoin(a);
data = xlsread(file);
x1 = data(:,1);
y1 = data(:,2);
y1sdupper = data(:,2) + data (:,3);
y1sdlower = data(:,2) - data (:,3);
y2 = data(:,4);
y2sdupper = data(:,4) + data (:,5);
y2sdlower = data(:,4) - data (:,5);
plot(x1, y1, 'r', x1, y2, 'b', x1, y1sdupper, 'r--', x1, y1sdlower, 'r--', x1, y2sdupper, 'b--', x1, y2sdlower, 'b--')
Cheers Matt
  1 commentaire
Star Strider
Star Strider le 7 Mai 2017
The patch function will shade the area you want.
I cannot run your code, and I have no idea what you actually want to do.

Connectez-vous pour commenter.

Réponse acceptée

Chad Greene
Chad Greene le 6 Sep 2017
Hi Matt,
I recommend Kelly Kearney's boundedline function. Just give it the central line and error values, and it figures out the rest. Like everything I've seen by Kelly, it's well designed and well documented.

Plus de réponses (1)

Maitreyee Mordekar
Maitreyee Mordekar le 16 Mai 2017
Hey,
Maybe the following links will help you implement your requirement:
  • https://in.mathworks.com/matlabcentral/answers/180829-shade-area-between-graphs
  • https://in.mathworks.com/matlabcentral/fileexchange/13188-shade-area-between-two-curves
  • https://in.mathworks.com/matlabcentral/answers/14005-how-can-i-shade-the-area-between-two-curve
Hope that helps!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by