Matlab vector of dynamic vectors

2019-08-27 17:39发布

问题:

I need to have a data structure such that i can quickly and repeatedly insert a number at a specific position (e.g. 5) in any list of a vector of lists and i do not know in advance how large will be each list. (the other positions of these lists may be empty). For example i could have a vector of dynamic lists (conceptually). I cannot preallocate a big matrix because it would be have in the order of 500K * 500K. but in any case i will only have at most 500K*500K elements in total but not known in advance in which lists/positions.

my questions is about a fast data structure. I am currently using (outerList is cellarry, and m,n integers):

outerList{label}=vertcat(outerList{label},[m n]);

here i am actually concatenanting a vector of 2 coords to my outerList, but i could reduce it to:

outerList{label}=[outerList{label}, N];

yet this is too slow.

My question boils down to : how can i do that faster?

标签: list vector