MATLAB: Input and output arguments in a function file

input output arguments function files variablesMATLAB

I have written a function file to give deflection (w) after a number of variables are inputted into a formula. my code is:
if true
% code
end
function w=function_project2[v t rd E p K]
%Function to find w (deflection)
% Input variables:
%v=poissons number
%t=plate thickness measured in metres
%rd=Radius of metal plate
%E=Young's modulus for selected material
%P=Pressure in kN
%K=Constant
%r=radial coordinate
%Output: variables
%w=deflection
w=(P*rd^4)/(64*K*(1+v)*(2*(3+v)*(1-(r/rd)^2)-(1+v)*(1-(r/rd)^4));
wmax=(P*rd^4*(5+v))/(64*K*(1=v)) end
The error coming up reads: function w=function_project2[v t rd E P K] | Error: Function definitions are not permitted in this context.
>>
1 Should my input variables and their values be listed in the function instead of the script file? 2 Have I completely misunderstood the input and output argument system? 3 pressure (p) has not yet been defined in the script or function. i am looking for it to increase in steps of 5000N until wmax is reached. How do i go about putting this into the formula? for loops?
Thanks, Mike

Best Answer

Where is that function defined?
If you have tried to define a function in a script file you would get that error (I just tested it and that is indeed the error mess\age you get in that case). A function must be defined in its own file named exactly the same as the function.
The exception is that you can have many functions defined in one function file, but only the one that shares the filename is publically accessible, the rest are subfunctions for use only by the main function of the file.
With regard to P you should be able to pass it in as a vector of values, but it may require some minor changes to your function code to work in vectorised form. Unfortunately I don't have time to look more deeply at that part of the question.