Thread Subject: add all the dimensions

Subject: add all the dimensions

From: Diego Lass

Date: 4 Sep, 2009 03:50:03

Message: 1 of 4

Hi

I am trying to add the matrices of different dimension together, ex

a(:,:,1)=
1 2 3
4 5 6

a(:,:,2) =
0 0 0
0 0 1

a(:,:,3) =
1 0 0
0 0 0

some function later gives
b =
2 2 3
4 5 7

what is the most efficient way of doing this?

Thanks!
Diego



 

Subject: add all the dimensions

From: dpb

Date: 4 Sep, 2009 03:55:18

Message: 2 of 4

Diego Lass wrote:
...

> what is the most efficient way of doing this?


sum(a,3)

--

Subject: add all the dimensions

From: Diego Lass

Date: 4 Sep, 2009 04:02:21

Message: 3 of 4

Got it! use sum(a,3);

"Diego Lass" <dlISCool@gmail.com> wrote in message <h7q2pb$qen$1@fred.mathworks.com>...
> Hi
>
> I am trying to add the matrices of different dimension together, ex
>
> a(:,:,1)=
> 1 2 3
> 4 5 6
>
> a(:,:,2) =
> 0 0 0
> 0 0 1
>
> a(:,:,3) =
> 1 0 0
> 0 0 0
>
> some function later gives
> b =
> 2 2 3
> 4 5 7
>
> what is the most efficient way of doing this?
>
> Thanks!
> Diego
>
>
>
>

Subject: add all the dimensions

From: Diego Lass

Date: 4 Sep, 2009 04:05:20

Message: 4 of 4

Got it! sum(a,3)
"Diego Lass" <dlISCool@gmail.com> wrote in message <h7q2pb$qen$1@fred.mathworks.com>...
> Hi
>
> I am trying to add the matrices of different dimension together, ex
>
> a(:,:,1)=
> 1 2 3
> 4 5 6
>
> a(:,:,2) =
> 0 0 0
> 0 0 1
>
> a(:,:,3) =
> 1 0 0
> 0 0 0
>
> some function later gives
> b =
> 2 2 3
> 4 5 7
>
> what is the most efficient way of doing this?
>
> Thanks!
> Diego
>
>
>
>

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com