[Top][All Lists]

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

Re: inconsitency in behavior of 'size'

From: Przemek Klosowski
Subject: Re: inconsitency in behavior of 'size'
Date: Mon, 12 Mar 2018 12:57:33 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0

On 03/10/2018 07:21 PM, Sergei Steshenko wrote:
"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.

Given the compatibility requirement that [] on the left of '=' is not the same as [] on the right size, it does make sense.

[a1,a2] = ... assigns two variables.

foo = [a1,a2] = ... is equivalent to

<return object> = ...

[a1,a2] = <return object>

foo = <return object>

In both of those cases, a1=[1;4], a2=[1;2], foo = [1;4]

foo = [a1, a2]

is different: foo = [1,1;4,2], because in this case [] is matrix concatenation. It's not really bad---it's just the way it is given Matlab design from back in the 1970s.

reply via email to

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