Is there a good way to avoid junking up code with lots of preallocation lines?
1 回表示 (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
採用された回答
Walter Roberson
2013 年 3 月 13 日
cash = struct('PaidOut', zeros(n,500), 'PaidIn', zero(n,500), 'TaxesPaid', zeros(n,500));
See also structfun()
0 件のコメント
その他の回答 (1 件)
Shaun VanWeelden
2013 年 3 月 13 日
You can assign the same value to multiple fields if you want, which I think would help in this case.
3 件のコメント
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!