[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Synonym
From: |
Markus Mützel |
Subject: |
Re: Synonym |
Date: |
Wed, 8 Apr 2020 19:17:11 +0200 |
Am 08. April 2020 um 18:07 Uhr schrieb "John W. Eaton":
> On 4/8/20 11:46 AM, "Markus Mützel" wrote:
>
> > I don't think it is necessary to initialize varargout. It should be
> > initialized to the correct length. [1]
> > This should be enough:
> >
> > function varargout = short (varargin)
> > [varargout{:}] = verylongname (varargin{:});
> > endfunction
>
> Can you verify that this function actually works in Matlab (see below
> for simple example)?
>
> > [1]: https://de.mathworks.com/help/matlab/ref/varargout.html
>
> The example on this page uses
>
> [varargout{1:nargout}] = ...
>
> which does work in Octave. But
>
> [varargout{:}] = ...
>
> fails in Octave unless varargout is explicitly initialized.
>
> And there is another example on that page that shows this:
>
> function varargout = variableNumInputAndOutput(varargin)
> disp(['Number of provided inputs: ' num2str(length(varargin))])
> disp(['Number of requested outputs: ' num2str(nargout)])
>
> If varargout is initialized when the function is called, then why use
> length (varargin) instead of nargin and nargout instead of length
> (varargout)?
>
> Can you try the following in Matlab to verify that varargout is initialized?
>
> function varargout = xsvd (varargin)
> numel (varargin)
> numel (varargout)
> [varargout{:}] = svd (varargin{:});
> end
>
> and then call it with
>
> xsvd (rand (2))
> s = xsvd (rand (2))
> [u, s, v] = xsvd (rand (2))
>
> Does that work? If so, I'll fix Octave to match that behavior.
It does not (tested with Matlab R2019b).
I thought it would be the expected behavior by reading this:
"When the function executes, varargout is a 1-by-N cell array, where N is the
number of outputs requested after the explicitly declared outputs."
But that clearly seems to be *not* the case. I must be misunderstanding what
that actually means...
Octave's current behavior is compatible to Matlab's.
Markus
- Re: Synonym, (continued)
- Re: Synonym, John W. Eaton, 2020/04/08
- Re: Synonym, Ian McCallion, 2020/04/08
- Re: Synonym, Doug Stewart, 2020/04/08
- Re: Synonym, Markus Mützel, 2020/04/08
- Re: Synonym, John W. Eaton, 2020/04/08
- Re: Synonym, Tony Richardson, 2020/04/08
- Re: Synonym, John W. Eaton, 2020/04/08
- Re: Synonym, Thomas D. Dean, 2020/04/08
- Re: Synonym, Kai Torben Ohlhus, 2020/04/09
- Re: Synonym, Thomas D. Dean, 2020/04/09
- Re: Synonym,
Markus Mützel <=