Can you preallocate an array of random size?
问题 The essential part of the code in question can be distilled into: list=rand(1,x); % where x is some arbitrarily large integer hitlist=[]; for n=1:1:x if rand(1) < list(n) hitlist=[hitlist n]; end end list(hitlist)=[]; This program is running quite slowly and I suspect this is why, however I'm unaware how to fix it. The length of the hitlist will necessarily vary in a random way, so I can't simply preallocate a 'zeros' of the proper size. I contemplated making the hitlist a zeros the length of