MATLAB: How to use polyarea

areapolyareasurface

hello,
I would need some help using the 'polyarea' function..
lets say: x=[1.5 1.25]; y=[570 363];
Plot(x,y) gives me a clear line, when is use area(x,y) I can visualize the area I want to calculate, but when I use polyarea(x,y), the answer is always 0 … Can anyone help me out ?

Best Answer

You need at least 3 points to have an area. Maybe you want the area below. Try this:
x=[1.5 1.25];
y=[570 363];
xTrap = [x(1), x(1), x(2), x(2)]
yTrap = [0, y(1), y(2), 0]
patch(xTrap, yTrap, 'r.-', 'LineWidth', 2);
grid on;
theArea = polyarea(xTrap, yTrap)