Plotting a trapezium in MATLAB
-
10-12-2019 - |
Question
How can I plot a figure in MATLAB such as a trapezium by giving only the vertices? I want the vertices connected by solid lines. I also want to calculate the area enclosed by the trapezium.
How can I do that?
Solution
use fill(x,y,colour)
fill([1,2,3,4],[6,3,4,9],"red")
or plot(x,y) with the first elements repeated at the end:
plot([1,2,3,4,1],[6,3,4,9,6])
Edit: for the area
polyarea([1,2,3,4],[6,3,4,9])
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow