Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: matrix with matrix for each element
Date: Tue, 15 Jul 2008 15:29:05 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 45
Message-ID: <g5ifo1$7qq$1@fred.mathworks.com>
References: <g5i9f9$eoo$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1216135745 8026 172.30.248.35 (15 Jul 2008 15:29:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 15 Jul 2008 15:29:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 791003
Xref: news.mathworks.com comp.soft-sys.matlab:479527



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