I can create the shaded boundary (y1 and Y2) individually but I have issues merging the two codes together. The data file is attached and the code is shown below. Thank you.
data=load('Jun15_VelocityUV.txt');
b= data(:,1);
y=b(104:127,:);
% Input x-axis
x = linspace(1,24,24);
xi=1:0.01:24;
yi=interp1(x,y,xi,'spline');
h=plot(xi,yi)
% Define Limit
y1=0.6;
y2 = -0.6;
hold on
%area(xi, min(yi, y2), y2,'EdgeColor', 'none', 'FaceColor', [.7 .7 .7])
hold on
area(xi, max(yi, y1), y1, 'EdgeColor', 'none', 'FaceColor', [.7 .7 .7])
hold off

 Accepted Answer

A few tweaks and it works:
data=load('Jun15_VelocityUV.txt');
b= data(:,1);
y=b(104:127,:);
% Input x-axis
x = linspace(1,24,24);
xi=1:0.01:24;
yi=interp1(x,y,xi,'spline');
% Define Limit
y1=0.6;
y1v = y1*ones(size(xi));
y2 = -0.6;
y2v = y2*ones(size(xi));
figure(1)
h=plot(xi,yi);
hold on
patch([xi(yi <= y2), fliplr(xi(yi <= y2))], [y2v(yi <= y2), fliplr(yi(yi <= y2))], [.7 .7 .7], 'EdgeColor', 'none')
patch([xi(yi >= y1), fliplr(xi(yi >= y1))], [y1v(yi >= y1), fliplr(yi(yi >= y1))], [.7 .7 .7], 'EdgeColor', 'none')
plot(xi, y1v, '-k', xi, y2v, '-k')
hold off

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects 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!