3

Is it possible in Matlab to create array of matrices which have different size. For example

Array_Mat(:,:,1) = zeros(3);
Array_Mat(:,:,2) = zeros(4);

This gives error. How I can make array of matrices then?

Roy
  • 65
  • 2
  • 15
  • 40

1 Answers1

7

You can use cells.

>> a{1}=[1 2 ;3 4]

a = 

    [2x2 double]

>> a{2}=zeros(4)

a = 

    [2x2 double]    [4x4 double]

>> a{1}(2,1)

ans =

     3

>> a{2}(3,4)

ans =

     0
jkt
  • 2,538
  • 3
  • 26
  • 28
  • How fast is this method in compare to regular one for large matrices? – Roy Nov 04 '12 at 23:37
  • 1
    @Hesam, I am not sure, you may want to try the cells vs 3-D matrices, i.e. try a{1}=randn(100,100) for a{1} up to a{1000} vs a=randn(100,100,1000). – jkt Nov 04 '12 at 23:41