Effacer les filtres
Effacer les filtres

How to preallocate memory if I don't know the size of the variable in every iteration?

1 vue (au cours des 30 derniers jours)
I have a large set of data, say A. I have a for loop. In every iteration, I'm going to only work with the subset of data of A, say A_sub, which are the elments of A that satisfy some conditions, such as within some ranges. Then, I'm also going to work with the subset of the A_sub, say A_sub_sub, which are the elements of A_sub that satisfy certain conditions, such as within some ranges. I don't know how many elements that's going to satisfy the certain condition, so I don't know the size of A_sub and A_sub_sub in advance. So the size of A_sub and A_sub_sub is going to change at each iteration. Is there a better way to do it?
  1 commentaire
Walter Roberson
Walter Roberson le 8 Juin 2019
You do not need to pre-allocate A_sub or A_sub_sub in those conditions, as you would be writing over all of them.
You would want pre-allocation if you were saving the results into a variable. In such a case, the best way to do pre-allocation would depend on how you want the saved information to be arranged relative to the other saved information.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by