Problem with a function.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Samy Ben Thabet
am 9 Okt. 2018
Beantwortet: James Tursa
am 9 Okt. 2018
I am trying to insert a function into my program but every time it tells me "error in perimeter line 3, p=4*s". Here is part of my program as well as my function. Can someone tell me what I am doing wrong? Thanks
function p=perimeter(s);
p=4*s;
end
into this part of my program:
h=input('What shape do you want?:','s');
if strcmp(h, 'square')
s=input('The length of a side is (m):');
A=s^2;
p=perimeter;
fprintf('The area of the Square is %.2f meters^2 \n',A)
fprintf('and the perimeter is %.2f meters\n',p)
0 Kommentare
Akzeptierte Antwort
James Tursa
am 9 Okt. 2018
You need to pass s into your perimeter function:
p = perimeter(s);
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Hypothesis Tests finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!