Preallocating cells with unknown output size
古いコメントを表示
I need to optimize my script. A thing I could do is preallocating, however the size of my output cell is unknown so my question is if it is worth it.
the output of the script is X, the size of X is not known.
Now I have:
X={};
*my script
X=nxn cell
If the output cell has the size 2x2 for example, can I do something like this:
not sure if it will increase the speed of my script
X=cell(999);
*my script
X=999x999 cell
*somehow reduce the size of X
X=2x2 cell
5 件のコメント
@Joel Schelander: what size (or range of sizes) do you expect the final output to be?
Joel Schelander
2021 年 4 月 12 日
@Joel Schelander: I am not expecting an exact size (otherwise the point of your question is moot). Most likely you can estimate the order of magnitude of how many cells you might expect (e.g. if you are processing image data, then the number of pixels places an upper limit on how many distinct objects can be represented in that image.
If we have an idea of the order of magnitude, then we can tailor our answers to help you better.
It makes a difference if your cell array is of the order one hundred cells vs one hundred million cells.
Joel Schelander
2021 年 4 月 12 日
Bruno Luong
2021 年 4 月 12 日
10 millions by 10 million cell?
I don't believe any existing HW can support that at the moment.
採用された回答
その他の回答 (1 件)
KSSV
2021 年 4 月 12 日
You can try to initilize them as
X = cell([],[]) ;
You can check the timing using tic , toc.
カテゴリ
ヘルプ センター および File Exchange で Univariate Discrete Distributions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!