From: us on
"Bruno Luong"
> %% The proper "beautiful" code is
> % We don't need the first output.
> % When the same variable is repeated on the lhs, the final value taken
> % corresponds to the most right, i.e. second output of f() here, since Matlab
> % affects from left to right out the output list (Attention: this convenstion
> % is opposite direction of arabic reading) .
> % Note: this is not documented, programmers who maintain this code
> % need to check this behavior stands consistently when for any newer Matlab
> % releases (twice a year) from now until year 3000.

smile...
bruno, i guess we leave it for now in saying:
TMW
- will NEVER EVER (or better, even:) CANNOT change this order of assignment...
why: because the whole syntax would break down
a=foo()
[a,b]=foo()
now: imagine all the changes in the code that needed to be made if indeed
[b,a]=foo()
and, therefore,
b=foo()
thus forcing changes within the engines...
- hence, the intro of the tilde op was nothing but a big, useless blunder
meant to deal with this very issue dealt with by CSSMers for decades already...
[unfortunately, as said above, the ~ sign now occupies a precious syntax item:
let's just hope that MLbbers are wise enough not to use this in order to
prevent having to wake-up one day to read the horrible release note saying:
sorry guys, the tilde now is used for something else - and really- useful]

as i said: with a smile
urs
From: Matt Fig on
"us " <us(a)neurol.unizh.ch> wrote in message
> - hence, the intro of the tilde op was nothing but a big, useless blunder
> meant to deal with this very issue dealt with by CSSMers for decades already...
> as i said: with a smile
> urs

Urs,

Except, as I said, when the dummy variable is the second returned output. In this case, there is no such syntax to keep the first returned arg and overwrite the second as in:

[a,a] = find(magic(5)==19) % We cannot get the row location only!

In this case, the tilde or clearing (as Bruno prefers) are the only choice. Here I would rather use the tilde!
From: Doug Schwarz on
In article <hi3bgv$bc1$1(a)fred.mathworks.com>,
"us " <us(a)neurol.unizh.ch> wrote:

[snip]

> bruno, i guess we leave it for now in saying:
> TMW
> - will NEVER EVER (or better, even:) CANNOT change this order of
> assignment...
> why: because the whole syntax would break down
> a=foo()
> [a,b]=foo()
> now: imagine all the changes in the code that needed to be made if indeed
> [b,a]=foo()
> and, therefore,
> b=foo()
> thus forcing changes within the engines...
> - hence, the intro of the tilde op was nothing but a big, useless blunder
> meant to deal with this very issue dealt with by CSSMers for decades
> already...
> [unfortunately, as said above, the ~ sign now occupies a precious syntax
> item:
> let's just hope that MLbbers are wise enough not to use this in order to
> prevent having to wake-up one day to read the horrible release note
> saying:
> sorry guys, the tilde now is used for something else - and really- useful]
>
> as i said: with a smile
> urs


I usually use something like

[unused,index] = sort(...)

because my intention is self-documented. Rarely do I clear unused
afterwards. If it was especially large I would.

Certainly we can always count on the output arguments matching the order
that they are listed in the function definition. The thing that is
undocumented, and therefore dangerous, is counting on the temporal order
being the same as the listed order. If TMW chooses to change MATLAB so
that in

[x_sorted,index] = sort(...)

the second argument is assigned before the first then that will surely
break

[index,index] = sort(...)

and I'm not willing to take the risk of having to change all my old code
-- especially the code that is in the possession of my clients! If it's
not documented behavior I don't do it. Period.

However, it's easy enough to wrap some of this up in a function:

------------------------------------------------------------
function varargout = argout(outargs,fcn,varargin)
% argout: Return selected output arguments.
%
% Syntax:
% [Y1,Y2,...] = argout(ARGS,FCN,X1,X2,...)
% will return the output arguments listed in the vector ARGS from the
% function FCN. ARGS must be a vector of integers and FCN must be a
% function handle.
%
% For example,
% indices = argout(2,@sort,x);
% can be used to return only the order index from the sort function
% which is normally the second output argument. You can even reverse
the
% order with
% [indices,x_sorted] = argout([2 1],@sort,x);

% written by Douglas M. Schwarz

m = max(outargs);
out = cell(1,m);
[out{:}] = fcn(varargin{:});
varargout = out(outargs);
----------------------------------------------------------


This will let you do

index = argout(2,@sort,x);

or even

[index,x_sorted] = argout([2 1],@sort,x);

if you choose. Because any unused arguments are assigned inside the
function they go away automatically. Still a one-liner, no clear
statement necessary.

--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.
From: Jos (10584) on
"Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message

> Btw, do we consider Jos as considered as junior or senior member? I consider myself and Jan as senior members - well relatively to some other. ;-)

For your information, I have been using ML for over 12 years now. This might make a senior for some ... and, although it is difficult to learn new tricks to an old dog, I am still learning a lot here.

Speaking of seniors, has anyone heard something from Roger Stafford lately?

Jos
From: Bruno Luong on
"Jos (10584) " <#10584(a)fileexchange.com> wrote in message <hi40ch$68p$1(a)fred.mathworks.com>...
>
> Speaking of seniors, has anyone heard something from Roger Stafford lately?
>

Roger showed up briefly few months ago then silence again. I wish him and everybody a happy new year.

Bruno