Fast rewrite all values in a large matrix.

Now for the purposes of this I'm looking at arrays of sizes(1e+8,50) so obviously very large.
In my code I am pre allocating a zeros matrix called A of data type 'uint8' because I'm not filling the array with numbers greater than 127 or less than 0.
My code rewrites entire columns of this array as such;
idx = [x:y];
%x and y are just two numbers like 1:3 or 5:18
A(1:end,idx) = group;
%group is just an array I have already figured out before hand
Is their a faster way to replace array contents than this, because this takes up the bulk of my run time

1 comentario

Try
A(:,idx) = group;
to eliminate the end intrinsic may help but it isn't needed.
I'd wonder if you couldn't fill A while building group instead of having second operation -- "the fastest operation is the one not made".

Iniciar sesión para comentar.

 Respuesta aceptada

Jan
Jan el 8 de Mayo de 2017
A(:, x:y) = group;
is faster than creating the index vector before. See http://www.mathworks.com/matlabcentral/answers/35676-why-not-use-square-brackets. But in your case the overhead of indexing is tiny compared to the real assiging.
The variable requires 5 GB of contiguos memory. Changing the values of all columns will take some time and this cannot be avoided. But the question remains, if it is useful at all to create such a huge redundant data set. Storing the indices and the value in small vectors will be much faster and more efficient. Do you really need this huge matrix?

1 comentario

Matthew Hickson
Matthew Hickson el 8 de Mayo de 2017
Yeah I don't need to represent the data this way and I even realised the stupidity of storing such large groups of data anyway so I restricted it to arrays only dozens of megabytes in size otherwise it represents the data as clusters. I figured there was no way to speed up this process since it's such a basic code execution but was hoping for some miracle

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 7 de Mayo de 2017

Comentada:

el 8 de Mayo de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by