Help with function that plots a specific shape and fills with specific color
5 次查看(过去 30 天)
显示 更早的评论
Create a MATLAB function called drawShape() that performs the following:
a. Displays a numbered list of shapes as shown below
b. Uses the inbuilt MATLAB function input()to request the user to
i. select a shape from this list, and
ii. a letter to indicate the color to fill the shape (for example: `r’ for red)
You should decide the dimensions of the shapes.
1. Right angled Triangle
2. Circle
3. Square
for example, drawShape(2,g) should plot a green circle.
The only thing I'm struggling with is ,for example, in drawShape(a,b) , how can the function be written for "a" to pull the specific shape plot, and "b" to fill the shape with a specific color.
0 个评论
回答(2 个)
Walter Roberson
2014-2-8
A shape with N sides can be built by taking points 360/N degrees apart on a circle.
When you create a shape, the operation you use will probably have a FaceColor property.
0 个评论
Image Analyst
2014-2-8
A triangle can be plotted with plot() or line().
A square can be plotted with plot(), line() or rectangle().
For any of them, you can use fill() or patch() to get solid shapes instead of just the perimeter.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!