문제

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