help-octave
[Top][All Lists]
Advanced

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

row vectors changed to column vectors?


From: John W. Eaton
Subject: row vectors changed to column vectors?
Date: Tue, 10 Feb 2004 09:17:13 -0600

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
-------------------------------------------------------------



reply via email to

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