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?

1
  • Likely a Duplicate. Commented Nov 4, 2012 at 23:08

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

2 Comments

How fast is this method in compare to regular one for large matrices?
@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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.