The ‘plan’ array is not being passed to your function, and since the function has its own workspace (that it does not share with the calling script workspace), ‘plan’ does not exist for it.
If you are passing ‘w’ and ‘l’ to your function, and not ‘plan’ either this option (that passes only the variables, not the array) —
function [result] = CalculateArea( w,l )
or this option (that passes the array) —
function [result] = CalculateArea( plan, i, j)
would likely work.
I cannot test this, so it will likely be necessary to experiment to determine the option that works best in your application.