[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Need test run in Matlab
From: |
Andrew Janke |
Subject: |
Re: Need test run in Matlab |
Date: |
Fri, 1 Feb 2019 06:04:23 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 |
On 1/31/19 3:05 PM, John W. Eaton wrote:
> On 1/29/19 2:39 PM, Christian Himpe wrote:
>> Here is the output of the corrected script.
>
> Thanks.
>
> I'm a bit confused by these results. Maybe I'm missing something, but I
> don't understand the case of f3(1), which shows that "sigma -1" is
> evaluated as a command. Compare this with f1(), which fails when there
> is a variable in the local workspace that conflicts with the name of the
> function (sigma). How does that make sense?
>
> Functions:
>
> function f1 ()
> sigma = svd (1);
> eval ('sigma -1;');
> end
>
> function f3 (sigma)
> eval ('sigma -1;');
> end
>
> function r = sigma (opt)
> global sigma_call;
> if (nargin == 0)
> sigma_call = 'function';
> r = 1;
> elseif (ischar (opt))
> sigma_call = 'command';
> r = 1;
> else
> sigma_call = 'unexpected';
> end
> end
>
> Output you sent for calling f1() and f3(1):
>
> f1: error: Error using f1 (line 3)
> Error: "sigma" was previously used as a variable, conflicting with its
> use here as the name of a function or command.
> See "How MATLAB Recognizes Command Syntax" in the MATLAB documentation
> for details.
> f1 (): none
>
> f3 (1): command
>
> Here are the functions:
>
> function f1 ()
> sigma = svd (1);
> eval ('sigma -1;');
> end
>
> function f3 (sigma)
> eval ('sigma -1;');
> end
>
> function r = sigma (opt)
> global sigma_call;
> if (nargin == 0)
> sigma_call = 'function';
> r = 1;
> elseif (ischar (opt))
> sigma_call = 'command';
> r = 1;
> else
> sigma_call = 'unexpected';
> end
> end
>
> Why should f3(1) succeed in calling sigma as a command-style function
> when f1() fails with an error message about sigma defined as a variable
> and later being used as a command-style function? Isn't sigma defined
> as a variable in both cases prior to the use as a function?
>
> jwe
>
I've got nothing. It's a surprise to me that f3(1) is not erroring. I
know that's not very helpful, but at least you're not overlooking
anything obvious as far as I can tell.
Cheers,
Andrew
- Re: Need test run in Matlab,
Andrew Janke <=