Speeding up large array element access/modification in class

4 visualizaciones (últimos 30 días)
Richard
Richard el 24 de Mzo. de 2011
Hi all,
So I have a class and one of its properties is an array which is initialised to:
large_array = zeros(1,1000000);
I also have a method in the class:
function log(this)
this.large_array(1,this.current_iteration) = this.some_value;
end
My problem is this method which updates a value in the array per iteration takes AGES (89.9% of the total program time). I am already preallocating the array so I do not understand why it is taking so long. So my questions are:
Why is this taking so long?
How can I speed the accessing/modifying up?
Thanks for your time, Richy

Respuestas (1)

Richard
Richard el 24 de Mzo. de 2011
Ok I found my answer, for anyone having the same problem take a look here:
This seems to be a bug with Matlab (I'm using R2010b).
The solution is to change the assignment so that the value you want to assign to the index in the large array is stored within the method temporarily. The updated method would look like this:
function log(this)
temp = this.some_value;
this.large_array(1,this.current_iteration) = temp;
end
I hope there's a patch or Matlab R2011a fixes this issue.

Categorías

Más información sobre Matrix Indexing 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