Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

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

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics