3

I have two matrices A1 and A2, for example A1 = [1 0; 1 1]; and A2 = [0 1; 1 1];

Now I don't want to have them called A1 and A2 since I will have An matrices.

So I wanted something like

A(1) = [1 0; 1 1]; A(2) = [0 1; 1 1]; .. A(n) = [...];

But Matlab does not allow me to do this.

I know one can use A(:,:,1) = [ ... ] but this is ugly and makes me type :,:, all the time... so I want to know if there is a different solution.

I tried A.1 but structs field names need to be strings.

2 Answers 2

6

Use cell array's:

A = cell(N, 1);

A{1} = [ 1 0; 1 1 ];
A{2} = [ 0 1; 1 1 ];
Sign up to request clarification or add additional context in comments.

Comments

3

You can use an array of structs.

A(1).mat = [1 0; 1 1];
A(2).mat = [0 0; 1 1];
...
A(n)...

or a cell array

A{1} = [1 0; 1 1];
A{2} = [0 1; 1 1];
...
A{n}...

Comments

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.