table block growth slow
7 views (last 30 days)
Show older comments
Hi,
I am trying to fill up a table with mixed data containing cashflows. each mortgage gets multiple lines. Preallocation of a similair table does not seem solve this problem. For preallocation i used repmat to create a table as large as the output containing dummy vars. Because dynamic allocation is complexer to read and gave no performance boost I decided to drop this approach.
The process of dynamically building the table starts out fairly fast but after 35000 iterations, where each adds blocks of about 360 new records, the perfomance decreases very fast. Takes about an hour or more.
enddataset = [dataset;newblock] % dynamic, slows over time
the tictoc slows down. now the weird stuff it that when I use struct it remains fast (11/12 minutes):
myStruct.iterationLabel = newblock. % does not slow over time
As I said using repmat and preallocation does not speed up.
Is it possible to grow a table in a fast manner?
0 Comments
Accepted Answer
Matt J
on 22 Jun 2018
Edited: Matt J
on 22 Jun 2018
If growing the object in struct form is fast enough for you, then a solution would be to build it as a struct first and then transform the final result using struct2table().
6 Comments
Peter Perkins
on 3 Jul 2018
I'm coming late to this thread, but two suggestions:
1) If you know the total size of the final table, you are much better off preallocating the right number of rows with zeros or whatever, and assigning into those rows. In R2018a, there's a new table constructor syntax for preallocation.
2) If that's not possible, you can save each block in a cell array of 360-row tables, and then vertcat(c{:}) all those tables into one at the end. This is usually quite fast.
More Answers (0)
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!