[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Need test run in Matlab
From: |
John W. Eaton |
Subject: |
Re: Need test run in Matlab |
Date: |
Thu, 31 Jan 2019 15:05:22 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 |
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
- Need test run in Matlab, John W. Eaton, 2019/01/28
- Re: Need test run in Matlab, Michele, 2019/01/28
- Re: Need test run in Matlab, John W. Eaton, 2019/01/29
- Re: Need test run in Matlab, John W. Eaton, 2019/01/29
- Re: Need test run in Matlab, Christian Himpe, 2019/01/29
- Re: Need test run in Matlab, John W. Eaton, 2019/01/29
- Re: Need test run in Matlab, Christian Himpe, 2019/01/29
- Re: Need test run in Matlab, John W. Eaton, 2019/01/29
- Re: Need test run in Matlab,
John W. Eaton <=