Is there a good way to avoid junking up code with lots of preallocation lines?
显示 更早的评论
I have a specific set of code that has a lot of little projection pieces, each of which I'd like to be preallocated for speed. However, in doing so, you get a lot of lines like this:
...
cash.PaidOut=zeros(n,500);
cash.PaidIn=zeros(n,500);
cash.TaxesPaid=zeros(n,500);
...
Is there a way to get the same functionality in a more terse style?
采纳的回答
更多回答(1 个)
Shaun VanWeelden
2013-3-13
0 个投票
You can assign the same value to multiple fields if you want, which I think would help in this case.
3 个评论
Shaun VanWeelden
2013-3-13
Multiple fields at one time/line if that was not clear before.
Walter Roberson
2013-3-13
Beware, though, the copy-on-write behavior.
Michael
2013-3-13
类别
在 帮助中心 和 File Exchange 中查找有关 Numeric Solvers 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!