MATLAB: Error Message: “Error: Function definitions are not permitted in this context.” How to fix this

error message

Hello, This is the function I have created function [R] = HydraulicRadius(W)
% ........
for D = 0.5:0.01:1.1
R=(W*D)/(W+2*D);
end
end
This is my input in the command window.
>> W=112.78;
>> function [R] = HydraulicRadius(W)
This is the output I get
??? function [R] = HydraulicRadius(W)
|
Error: Function definitions are not permitted in this context.
I'm not really sure why I am getting this error message. Any help would be greatly appreciated!

Best Answer

When you define a function in a file - you use the
function [R] = HydraulicRadius(W)
when you call it to use it, you do not use the word function as that is used for definition (aka your error message).
Call it like this:
R = HydraulicRadius(W)
(Note, you probably don't need the [], in the function definition)