0

Hello I am trying to create a simple array that contains a '10' 3x3 matrices. So I tried to create a 1D matrix that has 1 x 10 values. Then I tried assigning a 3x3 matrix in to each of the 10 slots in the 1D matrix. I am quite sure my syntax is wrong and matlab (I don't think allows this) but I couldn't find too much info to pre assign such array and I just started learning about matlab. Here is my attempt:

big_array = zeros(1,10) # creates 1x10 1d array
for i = 1:10
   big_array(i) = zeros(3,3); #supposedly? assign 3x3 matrix in to each of the 10 slots
end
big_array # received an error

2 Answers 2

1

If you know that you want an array of 10 3x3 matrices, you would typically want to use a multidimensional array from the start.

big_array = zeros(10,3,3);

You can access the i'th matrix using big_array(i,:,:).

If you really do want a one-dimensional array of 3x3 matrices, you need to use a cell array.

big_array = {};
for i = 1:10
   big_array{i} = zeros(3,3);
end
big_array

You can now access the i'th matrix using big_array{i}.

Sign up to request clarification or add additional context in comments.

Comments

1

A small clarification - If all your slots must contain submatrices with the same size, then you can use very simple expression:

big_array = zeros(3,3,10) % (first dimension - rows, second dimension - columns, third dimension - bands or arrays)

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.