[Top][All Lists]

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

Re: inconsitency in behavior of 'size'

From: Mike Miller
Subject: Re: inconsitency in behavior of 'size'
Date: Sat, 10 Mar 2018 11:15:25 -0800
User-agent: Mutt/1.9.3 (2018-01-21)

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.


Attachment: signature.asc
Description: PGP signature

reply via email to

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