[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: inconsitency in behavior of 'size'

From: Sergei Steshenko
Subject: Re: inconsitency in behavior of 'size'
Date: Sun, 11 Mar 2018 00:21:59 +0000 (UTC)

From: Mike Miller <address@hidden>
To: address@hidden
Sent: Saturday, March 10, 2018 9:16 PM
Subject: Re: inconsitency in behavior of 'size'

On Sat, Mar 10, 2018 at 13:26:18 +0000, Sergei Steshenko wrote:
> Because you are telling me that <FOO> and (<FOO>) are different.

No, if you read what I wrote, I said that they are exactly equivalent.
You are right that the parentheses don't change the value of FOO.

Let me try again to be very clear about what I have been telling you is

In the statement

    A = [x, y]

the syntax "[x, y]" creates a matrix by concatenating the values of x
and y. If x and y are each 4-by-1 vectors, "[x, y]" is a 4-by-2 matrix.
Here, the "[]" characters are acting as a concatenation operator.

In the statement

    [x, y] = sort((1:4)')

the syntax "[x, y]" does *not* create a matrix. On the left side of an
assignment, the "[]" characters are a different operator. It happens to
look like matrix concatenation, but it is not the same thing. x and y
have each been assigned the values of 4-by-1 vectors, but there is no
4-by-2 matrix. Adding parentheses around the whole statement and trying
to capture the value of concenating x and y isn't going to work because
no concatenation operation has happened.

I know you know this is true if you think about it, because a function
can return any number of values of different shapes and sizes that can't
be concatenated. In the case of sort, they happen to have the same size
and type, but there is no concatenation of return values.

> "it is a comma-separated list" - again, doesn't make sense to me.

The return value from a function is a comma-separated list, which is a
particular type in both Octave and Matlab. The syntax for slicing values
out of a comma-separated list looks a lot like matrix concatenation, but
it is not. That is a syntax confusion that Matlab created decades ago
and we have to keep it if we want to remain compatible.


Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:

"The syntax for slicing values out of a comma-separated list looks a lot like matrix concatenation" - which is obfuscation.

I.e. [foo, bar] should always mean the same. The situation is really bad - see copy-paste of a session:

octave:9> [a1, a2] = sort([1 2 3; 4 5 6](:,1))
a1 =


a2 =


octave:10> foo = [a1, a2] = sort([1 2 3; 4 5 6](:,1))
foo =



Output of command 9 shows TWO columns, while output of command 10 shows ONE column, and the difference is that in command 10 output of command 9 is assigned to a variable.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]