How can I make a function to input a polygon name and have the function plot the polygon?
Ältere Kommentare anzeigen
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!
Antworten (1)
Walter Roberson
am 15 Feb. 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')
Kategorien
Mehr zu Annotations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!