From: dpb on
Walter Roberson wrote:
....

> Amplifying slightly:
>
> program.m
>
> could cause the function named "program" to run with no arguments, and
> then attempt to access the field "m" of the result.

Is that behavior in current versions of ML, Walter? In R12, trying
somematlabfunction.m for any function that doesn't require an input
argument either returns

??? Undefined variable 'somematlabfunction'.

if there isn't a variable in the workspace masking the function or

??? Attempt to reference field of non-structure array 'somematlabvariable'

if it is a variable in the workspace.

I think (but forgot to mention) he has inadvertently created a variable
"program" and should do a

which program

in the workspace command line to confirm/deny that hypothesis.

--
From: Andy on
> Is that behavior in current versions of ML, Walter? In R12, trying
> somematlabfunction.m for any function that doesn't require an input
> argument either returns
>
> ??? Undefined variable 'somematlabfunction'.
>
> if there isn't a variable in the workspace masking the function or
>
> ??? Attempt to reference field of non-structure array 'somematlabvariable'
>
> if it is a variable in the workspace.
>
> I think (but forgot to mention) he has inadvertently created a variable
> "program" and should do a
>
> which program
>
> in the workspace command line to confirm/deny that hypothesis.
>
> --

In MATLAB R2009a, running:

>> myFunction.m

for myFunction in the current directory ran myFunction and then returned the error

??? Attempt to reference field of non-structure array

On the other hand, if I defined:

>> myFunction = 2;
>> myFunction.m

I get just the error code (myFunction did not run first). Based on the OP's description, I would guess he does not have a variable masking program.m, since his program seems to run to completion before the error.
From: CuLa on
Silly me, thank you.
From: dpb on
Andy wrote:
>> Is that behavior in current versions of ML, Walter? In R12, trying
>> somematlabfunction.m for any function that doesn't require an input
>> argument either returns
>>
>> ??? Undefined variable 'somematlabfunction'.
>>
>> if there isn't a variable in the workspace masking the function or
>>
>> ??? Attempt to reference field of non-structure array
>> 'somematlabvariable'
>>
>> if it is a variable in the workspace.
>>
....
> In MATLAB R2009a, running:
>
>>> myFunction.m
>
> for myFunction in the current directory ran myFunction and then returned
> the error
> ??? Attempt to reference field of non-structure array
>
> On the other hand, if I defined:
>
>>> myFunction = 2;
>>> myFunction.m
>
> I get just the error code (myFunction did not run first). Based on the
> OP's description, I would guess he does not have a variable masking
> program.m, since his program seems to run to completion before the error.

That's interesting change in behavior. I'll allow as how I somewhat
puzzled at the sequence of the interpreter resolving the command now
that it seems from the description to result in essentially to
invocations of the functionname; one that runs the m-file function and
the resultant to try to find the structure...as opposed to the R12
behavior described which aborts in what appears to me a more logical
manner.

That the function actually was getting executed I put down to a mistaken
understanding of a symptom when seeing the cause but apparently not in
new/current versions. Have to try to remember that down the road if
similar queries arise...

--
From: Andy on
I should also point out that this behavior acts "appropriately" if the function happens to return a structure:

% in a separate m-file
function a=myFunction
a.f1=3;
a.f2=5;
end


% at the command line
>> myFunction.f1
ans =
3

But I have to say I think I would rather this return an error. This seems like it could lead to eval-like, difficult-to-debug errors.