how to solve Function definitions are not permitted in this context

hello guys i have homework and i got this problem in my code Error Function definitions are not permitted in this context
and this is my code
function [] = ans2()
rads = randi([1, 20], 1, 5); areas = rads .^ 2 * pi;
for i = 1:1:5 fprintf('For radius: %0.4f area is %0.4f.\n', rads(i), areas(i)); end end
i need your help guys .

Respuestas (1)

madhan ravi
madhan ravi el 5 de Nov. de 2018
Editada: madhan ravi el 5 de Nov. de 2018
ans2() %function calling
function ans2()
rads = randi([1, 20], 1, 5);
areas = rads .^ 2 * pi;
for i = 1:5
fprintf('For radius: %0.4f area is %0.4f.\n', rads(i), areas(i));
end
end

4 comentarios

You shouldn’t copy and paste it in command window , instead save it as a script file and then run using the green button
thank you so much for your help
madhan ravi
madhan ravi el 5 de Nov. de 2018
Editada: madhan ravi el 5 de Nov. de 2018
Anytime :), if it helped make sure to accept the answer so that people know the question is solved

Iniciar sesión para comentar.

Categorías

Más información sobre Wavelet Toolbox en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 5 de Nov. de 2018

Editada:

el 5 de Nov. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by