MATLAB: Does a local function variable matter

beginnerfunctionmatlab functionnamingpotato

When I am creating a function, does the variable I used to define it matter? When I call it in a script, I use it as the file name I saved it as. For example:
function E1=E_Voight(Vr,Em,Er)
E1=Er*Vr+Em*(1-Vr);
end
This is my function, I refer to it by its file save name (also E_Voight), but could I redefine this entire function using only x, y, z and change the file name to "Potato" and refer to it in a script as "Potato(1,2,3)" and the variables x,y,z used to define the function would not interfere with a variable that I had named x in my script?

Best Answer

Each function has its own workspace that does not interact with other workspaces unless you use evalin() or assignin(), or you use a global variable, or you use a shared variable (which requires nested functions.)
So yes, it is correct, if you were to define
function E1 = Potato(x, y, z)
then the x from the function definition would not interfere with any x in the script. The function cannot reach the variables in the script other than the ways I listed before. For example if you were to define
function E1=E_Voight(Vr,Em,Er)
E1=Er*Vr+Em*(1-Vr) + x;
then this would be treated as an undefined x (unless there happened to be a function named x): MATLAB would not look outside at the calling routine to try to find an x there.