help-octave
[Top][All Lists]

## Re: inconsitency in behavior of 'size'

 From: Sergei Steshenko Subject: Re: inconsitency in behavior of 'size' Date: Fri, 9 Mar 2018 21:42:37 +0000 (UTC)

```

________________________________
Sent: Friday, March 9, 2018 9:28 PM
Subject: Re: inconsitency in behavior of 'size'

On Fri, Mar 09, 2018 at 18:37:02 +0000, Sergei Steshenko wrote:
> Pay attention that in both cases essentially size of [_1,_2]
> expression is calculated, but in the first case the expression is also
> first assigned its value from call to 'sort' while in the second case
> it's just the expression.

I think it might help first to agree that '[x,y]' is syntax that
declares an array, but '[x,y] = something' is a different assignment
syntax that assigns two return values to x and y independently.

If you have a background in C you might assume that the *value* of the
overall assignment expression is the same as the value '[x,y]'. But it's
very important to note that '[x,y]' in assigment syntax is not actually
instantiating an array composed from x and y.

Now, compare the values of the following

([_1,_2] = sort(im(:, 3), "descend"))
([_1,_2] = sort(im(:, 3), "descend"))(:)
[[_1,_2] = sort(im(:, 3), "descend")]
{[_1,_2] = sort(im(:, 3), "descend")}

I don't have any documentation or code to point at, but I would venture
to say that when an assignment to multiple return values is used in
another expression, the value of the expression is that of the first
return value only.

> How does Matlab behave in the same case ?

Matlab does not allow assignments to be used as expressions.

--
mike

-----------------------------------------
https://wiki.octave.org/OctConf_2018

-----------------------------------------

"
I think it might help first to agree that '[x,y]' is syntax that
declares an array, but '[x,y] = something' is a different assignment
syntax that assigns two return values to x and y independently" - I don't agree
with that. Because the final result, which is
[_1,_2], is the same - regardless whether I do the assignment as

([_1,_2] = sort(im(:, 3), "descend"))

or

[_1,_2] = sort(im(:, 3), "descend").

Really, don't create the entities beyond the necessary, i.e. don't change type
beyond the necessary.

Thanks,
Sergei.

```