Preallocation of a matrix: how to shrink it afterwards?

5 visualizaciones (últimos 30 días)
Samuele Bolotta
Samuele Bolotta el 11 de Mayo de 2020
Comentada: Walter Roberson el 11 de Mayo de 2020
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

Respuestas (1)

per isakson
per isakson el 11 de Mayo de 2020
Editada: per isakson el 11 de Mayo de 2020
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?

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by