Pre-allocating speed for an array that change size on every loop iteration
Mostrar comentarios más antiguos
I have got a big matrix (1000x1000 for instance) and I want to get all the elements of the even columns. So I create that loop, but because of the lack of speed, it never gets finished.
Matrix = randi([0, 1], [1000,1000]);
[row,column]=size(Matrix);
VectorValue=[];
for i=1:1:row
for j=1:2:column
ValueEven=Matrix(i,j); %Get the value of actual even column
VectorValue=[VectorValue, ValueEven]; %Put that value in an array of all the values of the even columns
end
end
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!