how to solve Function definitions are not permitted in this context
Show older comments
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)
madhan ravi
on 5 Nov 2018
Edited: madhan ravi
on 5 Nov 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 Comments
madhan ravi
on 5 Nov 2018
You shouldn’t copy and paste it in command window , instead save it as a script file and then run using the green button
Turki Ali
on 5 Nov 2018
madhan ravi
on 5 Nov 2018
Edited: madhan ravi
on 5 Nov 2018
Anytime :), if it helped make sure to accept the answer so that people know the question is solved
Categories
Find more on Wavelet Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!