Вопрос

I'm following the most voted answer of the question at the link below but I'm not getting anywhere. MATLAB, Filling in the area between two sets of data, lines in one figure

I want fill the area between one horizontal line y=6 and other horizontal line y=9

x=ones(1,110)                  %#initialize x array
y1=6*(x);                      %#create first curve 
y2=9*(x);                      %#create second curve
X=[x,fliplr(x)];               %#create continuous x value array for
Y=[y1,fliplr(y2)];             %#create y values for out and
fill(X,Y,'b');                 %#plot filled area

Simply it's not working! Any idea why not?

Это было полезно?

Решение 2

Your code could be simplified:

area([1 110],[9 9],6)    % plot a line between (x1,y1) and (x2,y2), then fill down to a baseline (6)
ylim([0 10])             % scale y axis to fit

For straight lines, you only need two points, not 110.

Другие советы

You are nearly there.

X should contain the index of the x-points (1:110) and not ones(110).

X=[1:110,fliplr(1:110)];

gives

enter image description here

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top