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