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

3 次查看(过去 30 天)
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

采纳的回答

Chad Greene
Chad Greene 2017-9-6
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.

更多回答(1 个)

Maitreyee Mordekar
Maitreyee Mordekar 2017-5-16
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!

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by