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 .

Answers (1)

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 Comments

You shouldn’t copy and paste it in command window , instead save it as a script file and then run using the green button
Anytime :), if it helped make sure to accept the answer so that people know the question is solved

Sign in to comment.

Categories

Find more on Wavelet Toolbox in Help Center and File Exchange

Tags

Asked:

on 5 Nov 2018

Edited:

on 5 Nov 2018

Community Treasure Hunt

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

Start Hunting!