Preallocation of a matrix: how to shrink it afterwards?
4 次查看(过去 30 天)
显示 更早的评论
I'm trying to create an empty epoch for every epoch number in epochn - epochn is a nx1 matrix. How can I preallocate fullstate efficiently? Thanks!
%Create empty epoch for every epoch number
for t = epochn
idx = find(epochn == t);
fullstate(t) = state(idx);
clear idx
end
回答(1 个)
per isakson
2020-5-11
编辑:per isakson
2020-5-11
Something like this
fullstate = class_of_state( size(epochn) );
for t = reshape( epochn, 1,[] )
idx = find(epochn == t);
fullstate(t) = state(idx);
clear idx
end
The variable, state, what type of values does it have?
"shrink it afterwards" why would that be necessary?
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!