sum element of columns

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

sum element of columns

turbofib

a =

   9   1   6
   3   6   2
   1   9   8


i want this:


newArray=9+1+6;3+6+2;1+9+8

=15 11 18



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: sum element of columns

apjanke-floss


On 10/16/18 2:15 AM, turbofib wrote:

> a =
>
>     9   1   6
>     3   6   2
>     1   9   8
>
>
> i want this:
>
>
> newArray=9+1+6;3+6+2;1+9+8
>
> =15 11 18
>
>
>
The sum() function takes an argument that lets you control which
dimension it sums along. Try `sum(a, 2)'`.


octave:4> sum(a, 2)'
ans =

    16   11   18

See `help sum` for details.

Cheers,
Andrew


Reply | Threaded
Open this post in threaded view
|

Re: sum element of columns

marco atzeri-2
In reply to this post by turbofib
Am 16.10.2018 um 08:15 schrieb turbofib:

>
> a =
>
>     9   1   6
>     3   6   2
>     1   9   8
>
>
> i want this:
>
>
> newArray=9+1+6;3+6+2;1+9+8
>
> =15 11 18
>

maybe it is time to lean matrix multiplication ?

a= [9 1 6 ; 3 6 2 ; 1 9 8 ]
a =

    9   1   6
    3   6   2
    1   9   8

octave:2> b = [ 1;1;1]
b =

    1
    1
    1

octave:3> a*b
ans =

    16
    11
    18


---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus



Reply | Threaded
Open this post in threaded view
|

Re: sum element of columns

turbofib
In reply to this post by apjanke-floss
thank you

i ask you another question ;

a[1 4 6 3; 6 5 4 3;9 7 3 5; 3 4 1 3]

i want this:



3    3+6   3+6+4  3+6+4+1   first row

3    3+4   3+4+5  3+4+5+6   second row

5    5+3   5+3+7  5+3+7+9   third row

3    3+1   3+1+4  3+1+4+3   four row


result=

B=[3 9 13 14;3 7 12 18;5 8 15 24;3 4 8 11]  




--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: sum element of columns

Montgomery-Smith, Stephen

b = a * flip(triu(ones(size(a)(2))))


From: Help-octave <help-octave-bounces+stephen=[hidden email]> on behalf of turbofib <[hidden email]>
Sent: Tuesday, October 16, 2018 5:54:33 PM
To: [hidden email]
Subject: Re: sum element of columns
 
thank you

i ask you another question ;

a[1 4 6 3; 6 5 4 3;9 7 3 5; 3 4 1 3]

i want this:



3    3+6   3+6+4  3+6+4+1   first row

3    3+4   3+4+5  3+4+5+6   second row

5    5+3   5+3+7  5+3+7+9   third row

3    3+1   3+1+4  3+1+4+3   four row


result=

B=[3 9 13 14;3 7 12 18;5 8 15 24;3 4 8 11] 




--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html




Reply | Threaded
Open this post in threaded view
|

Re: sum element of columns

marco atzeri-2
In reply to this post by turbofib
Am 17.10.2018 um 00:54 schrieb turbofib:

> thank you
>
> i ask you another question ;
>
> a[1 4 6 3; 6 5 4 3;9 7 3 5; 3 4 1 3]
>
> i want this:
>
>
>
> 3    3+6   3+6+4  3+6+4+1   first row
>
> 3    3+4   3+4+5  3+4+5+6   second row
>
> 5    5+3   5+3+7  5+3+7+9   third row
>
> 3    3+1   3+1+4  3+1+4+3   four row
>
>
> result=
>
> B=[3 9 13 14;3 7 12 18;5 8 15 24;3 4 8 11]
>
>
octave:1> a=[1 4 6 3; 6 5 4 3;9 7 3 5; 3 4 1 3]
a =

    1   4   6   3
    6   5   4   3
    9   7   3   5
    3   4   1   3

octave:2> b=[0 0 0 1; 0 0 1 1 ; 0 1 1 1; 1 1 1 1]
b =

    0   0   0   1
    0   0   1   1
    0   1   1   1
    1   1   1   1

octave:3> a*b
ans =

     3    9   13   14
     3    7   12   18
     5    8   15   24
     3    4    8   11

---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus