Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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 Commento
Walter Roberson
Walter Roberson il 8 Giu 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.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by