How can I make a function to input a polygon name and have the function plot the polygon?
Mostrar comentarios más antiguos
I am trying to create a code that will be able to plot a polygon by imputing the name. For example: PlotThePolygon(Triangle) . Any help is appreciated!
Respuestas (1)
Walter Roberson
el 15 de Feb. de 2016
function gonname = Triangle
gonname = 'Triangle';
function gonname = Square
gonname = 'Square';
function gonname = Pentagon
gonname = 'Pentagon';
function PlotThePolygon(gonname)
switch(gonname)
case 'Triangle'
... %appropriate plotting here
case 'Square'
... %appropriate plotting here
case 'Pentagon'
... %appropriate plotting here
otherwise
fprintf('I do not know how to plot something named a "%s"\n', gonname);
end
The first functions exist solely for the purpose of allowing the user to omit the quotation marks around what needs to be a string, since PlotThePolygon(Triangle) is asking PlotThePolygon to work upon the result of executing a function named "Triangle" and what it really needs is to be called like PlotThePolygon('Triangle')
Categorías
Más información sobre Elementary Polygons en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!