# I keep receiving an error saying "execution of script drawpolygon as a function is not supported", even though it has previously worked.

1 vue (au cours des 30 derniers jours)
ISABELLE GUNDRUM le 7 Mar 2022
Commenté : KSSV le 7 Mar 2022
My code:
for k=1:3
c{k} = zeros(1,3);
end
for k = 1:3
tmp = input(['Press any key to draw Polygon # ' int2str(k) ': ']);
close all, imshow(I), title(['Polygon # ' int2str(k)])
h = drawpolygon;
% The vertices of k-th polygon is recorded in polyin{k}
polyin{k} = polyshape(h.Position); % create a polygon object
[cx,cy] = centroid(polyin{k});
c{k}(1:2) = round([cx cy],0); % unit: pixels
c{k}(3) = round(area(polyin{k}),0)*p2cm; % unit: cm^2
if k==3
tmp = input('Press any key to complete.')
end
disp(['Centroid of polygon: [' int2str([cx cy]) ']'])
disp(['Area of polygon = ' int2str(c{k}(3)) 'cm^2'])
end
The error: The code is being used to draw 3 different polygons on one image.
Thanks!
##### 0 commentairesAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

KSSV le 7 Mar 2022
Modifié(e) : KSSV le 7 Mar 2022
It looks like you have named the present code as drawpolygon. No you should not name it on that name as drawpolygon is a inbuilt function. Rename the present file into a different name, then run and see.
##### 2 commentairesAfficher 1 commentaire plus ancienMasquer 1 commentaire plus ancien
KSSV le 7 Mar 2022
Thanks is accepting / voting the answer.

Connectez-vous pour commenter.

### Plus de réponses (1)

Jan le 7 Mar 2022
Modifié(e) : Jan le 7 Mar 2022
The message means, that drawpolygon is a script. Then it does not have input nd output arguments:
h = drawpolygon;
% ^^^ omit this
But you do need the handle h later. Therefore I guess, that the line, which defines the script as a function was deleted by accident. What is the contents of drawpolygon.mlx?
##### 0 commentairesAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Programming dans Help Center et File Exchange

R2021a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!