I have observed a strange behavior in running the same code in a Matlab function and in the command window. It's already described in How does scoping in Matlab work? , but I don't understand how I could solve my specific problem. The code is the following:
exporteddata.m  %File created by an external program 
                %to export data in Matlab format
surface = struct('vertices', [...]) ; 
                         %I can't specify in the external program 
                         %the name of the variable, it's always "surface"
My actual code is:
   myfunction.m 
   function output = myfunction(input)
   load(input);
   n = size(surface.vertices);
  ....
When running
myfunction('exporteddata.m'); 
I get the following error:
??? No appropriate method, property, or field vertices for class hg.surface.
When running the same instructions from the command window or in debug mode, the code works well.
How can I specify in the function that I need the variable surface present in the workspace, not the Matlab function?