help-octave
[Top][All Lists]
Advanced

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

## Re: Unidentified subject!

 From: Paul Kienzle Subject: Re: Unidentified subject! Date: Sun, 15 Feb 2004 01:33:10 -0500

```
On Feb 15, 2004, at 12:20 AM, Avraham Rosenberg wrote:

```
```Hi,
```
Paul Kienzle and Andy Adler mentioned recently the possibility of forcing
```the creation of a column vector by using the symbol x(:).
```
Could anyone give an example, please ? I tried x(:)=sort([1,5,8,4,2]) and I got a sorted row vector (Octave-2.1.50 on debian stable). Apparently I
```misunderstood those answers.
```
```
First let's make sure we are using the same terminology:

a column vector is N x 1, or a single column matrix
a row vector is 1 x M, or a single row matrix

Next, understand that the following does not affect the shape
of x:

x(:) = y;

It instead does an element-wise copy from y to x in order
so long as x and y are the same size, no matter what the
shape of either.  E.g.,

octave> x=zeros(2,2);
octave> x(:)=1:4
x =
1  3
2  4

However, as an expression, x(:) converts x into a column vector:

octave> x(:)
ans =
1
2
3
4

and x(:).' converts x into a row vector:

octave> x(:).'
ans =
1  2  3  4

This even works on expressions (at least in Octave):

octave> sort([1,5,8,4,2])
ans =
1  2  4  5  8

octave> sort([1,5,8,4,2])(:)
ans =
1
2
4
5
8

Paul Kienzle
address@hidden

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