help-octave
[Top][All Lists]

## Re: row vectors changed to column vectors?

 From: Jonathan Stickel Subject: Re: row vectors changed to column vectors? Date: Tue, 10 Feb 2004 07:57:26 -0800 User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031226

As a former Matlab user, I remember being frustrated with row vectors begin the default. So I got in the habit of always assigning vector elements like this:
```
a(1,1)=1;
a(2,1)=2;
a(3,1)=3;
(etc.)

Then I got what I wanted and avoided confusion.

Jonathan

John W. Eaton wrote:
```
```On 10-Feb-2004, Christian T. Steigies <address@hidden> wrote:

| I wrote a little function to generate maximum length pseudo random
| sequences, the function returns a vector. I am doing some matrix
| multiplication with this vector and notice that in octave 2.1.50 the vector
| is treated as row vector, whereas in 2.1.53 it is treated as a column
| vector. Simple example:
```
| | octave:1> a(1)=1
```| a = 1
| octave:2> a(2)=2
| a =
```
| | 1
```|   2
```
| | octave:3> version | ans = 2.1.50
```| octave:4> [nr,nc]=size(a)
| nr = 2
| nc = 1
```
| | | octave:1> a(1)=1
```| a = 1
| octave:2> a(2)=2
| a =
```
| | 1 2 | | octave:3> version
```| ans = 2.1.53
| octave:4> [nr,nc]=size(a)
| nr = 1
| nc = 2
```
| | Is this expected behaviour and if so is it going to stay that way? A quick
```| search didn't show anything in the changelog, but maybe I was looking for
| the wrong thing.

Yes, this change is permanent, for compatibility with Matlab.  In the
past, you could use the built-in variable prefer_column_vectors to
choose what Octave would do for things like

clear a; a(1)=1; a(2)=2

but now Octave will only do the Matlab-compatible thing and create row
vectors.

Other than the potential compatibility problems, the existence of a
variable like prefer_column_vectors made it harder to write code that
would work no matter which preference other users might have.  So it
was best to eliminate the variable.

BTW, if you are creating vectors by doing things like

clear a;
for i = 1:N
a(i) = something();
end

then you should probably rethink your method, because this type of
loop the vector A to be resized N times, which will be slow.

jwe

-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

```
```

-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

```