Thread Subject: matrix with matrix for each element

Subject: matrix with matrix for each element

From: Dave Brackett

Date: 15 Jul, 2008 13:42:01

Message: 1 of 3

Hi, I am trying to create a matrix which has a matrix as
each element e.g.:

h=[1:3]'
h(1)=[1,2;3,4]

I then get this message which is understandable:
??? In an assignment A(I) = B, the number of elements in B and
 I must be the same.


Is there a way to do this though?
Thanks in advance.

Subject: matrix with matrix for each element

From: John D'Errico

Date: 15 Jul, 2008 13:54:02

Message: 2 of 3

"Dave Brackett" <davebrackett@hotmail.com> wrote in message
<g5i9f9$eoo$1@fred.mathworks.com>...
> Hi, I am trying to create a matrix which has a matrix as
> each element e.g.:
>
> h=[1:3]'
> h(1)=[1,2;3,4]
>
> I then get this message which is understandable:
> ??? In an assignment A(I) = B, the number of elements in B and
> I must be the same.
>
>
> Is there a way to do this though?
> Thanks in advance.

help cell

John

Subject: matrix with matrix for each element

From: David

Date: 15 Jul, 2008 15:29:05

Message: 3 of 3

"Dave Brackett" <davebrackett@hotmail.com> wrote in
message <g5i9f9$eoo$1@fred.mathworks.com>...
> Hi, I am trying to create a matrix which has a matrix as
> each element e.g.:
>
> h=[1:3]'
> h(1)=[1,2;3,4]
>
> I then get this message which is understandable:
> ??? In an assignment A(I) = B, the number of elements
in B and
> I must be the same.
>
>
> Is there a way to do this though?
> Thanks in advance.

you can do 3d arrays, here is a crude example...

m=zeros(3,2,2);
m(1,:,:)=[1,2;3,4];
m(1,:,:)

ans(:,:,1) =
     1 3
ans(:,:,2) =
     2 4

m(2,:,:)
ans(:,:,1) =
     0 0
ans(:,:,2) =
     0 0

m(3,:,:)
ans(:,:,1) =
     0 0
ans(:,:,2) =
     0 0

  
of course this is restricted to all the sizes being the
same. cells are nicer in some ways, it depends on just
what your requirements are.

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