help-octave
[Top][All Lists]

## Re: simple (not for me) operation on matrix

 From: Jonathan C. Webster Subject: Re: simple (not for me) operation on matrix Date: Tue, 13 May 2003 12:53:24 -0400 User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 (NSCD7.01)

```

Paolo Ariano wrote:
```
```hi *

ive a big matrix (750 cols* 140 rows) for example:

1 2 3 2 4 5 6
3 4 6 5 3 2 1
2 4 5 6 7 8 8
6 7 5 4 3 2 1

i need to obtain a new matrix where i sum line 1 and line 2, then line 3
and line 4 and so on as:

(1+3) (2+4)
(2+6) (4+7)

```
```
```
Sometimes reshape and transpose can be faster than looping and indexing.
```Try this.  I left out the numerical responses.
#origional matrix
aa = rand(6, 3)

# reshape transpose
raap = reshape (aa',6,3)

#You now wish to .+ the top 3 rows to the bottom 3 rows
# and transpose the result

qq1 = raap(1:3,:)
qq2 = raap(4:6,:)
ssum = ( qq1 .+ qq2)'

You can probably get that down to one or two lines.

Hope that helps,
Jonathan

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