I would like to make multiple arrays with different dimensions in Matlab.
Is there a way to do this inside a “for” loop?
For example, I would like to create a matrix A with dimensions 100×100, then with 200×200,etc
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Try using the
zerosfunction instead of creating your array inside of a loop.Something like:
This will be much faster initially (since the array is not having to be resized every time you add an element); you can then iterate over it later and add whatever values you need.
EDIT: I should clarify, the zeros function creates an m X n matrix (or an array if you leave off the second argument) and fills it with all zeros. It’s a good starting point for constructing large arrays.