Speeding up large array element access/modification in class

조회 수: 4 (최근 30일)
Richard
Richard 2011년 3월 24일
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

답변 (1개)

Richard
Richard 2011년 3월 24일
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.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by