Issues with area function to fill under plot
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
simplified
am 19 Okt. 2017
Beantwortet: Star Strider
am 19 Okt. 2017
Consider the following code:
xData = rand(100,1)*0.5;
yData = linspace(2000,2500,100);
figure(1)
plot(xData,yData)
which produce the following figure (after resizing it slightly horizontally):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/168470/image.png)
Now, I want to basically fill the area under the curve, i.e. between x=0 and the curve. So, when I try the area function:
figure(2)
area(xData,yData)
I get the following figure (which is obviously not what I want):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/168471/image.png)
What am I doing wrong?
0 Kommentare
Akzeptierte Antwort
Star Strider
am 19 Okt. 2017
Try this:
y = 0:20;
x = rand(size(y));
figure(1)
plot(x, y)
hold on
patch([ zeros(size(x)) x ], [ fliplr(y) y ], 'g')
hold off
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!