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

2 ビュー (過去 30 日間)
Matt King
Matt King 2017 年 5 月 7 日
回答済み: Chad Greene 2017 年 9 月 6 日
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 件のコメント
Star Strider
Star Strider 2017 年 5 月 7 日
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.

サインインしてコメントする。

採用された回答

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 Center および File ExchangeDirected Graphs についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by