Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Reducing time code takes to run using profile viewer

1 Ansicht (letzte 30 Tage)
Paul
Paul am 12 Feb. 2012
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
This code below takes up about 40 seconds when the size of the matrix is (13,5,2000) All im doing is removing any matrixs which are repeated.
ie if big_data(:,:,x)==big_data(:,:,x+1) then remove one of the matrixs. I know there is a unique function, but I cant seem to get it to work how I want. When I scale it up to matrixs of size (13,5,10000), its just taking too long.
Is there a better way? thanks.
while x<length(big_data(1,1,:))+1
while y<length(big_data(1,1,:))
y=y+1;
if big_data(:,:,x)==big_data(:,:,y)
big_data(:,:,y)=[];
y=y-1;
end
end
x=x+1;
y=x;
end

Antworten (2)

Jan
Jan am 12 Feb. 2012
Shrinking a large array iteratively requires a lot of resouerces, equivalently to growing. Better use a logical vector to mark subarrays and delete them all together after the loops.

Paul
Paul am 14 Feb. 2012
Are you saying to do something like, replace
big_data(:,:,y)=[];
with
to_delete(count)=y
then once the loop is finished
big_data(:,:,to_delete)=[]
  1 Kommentar
Sean de Wolski
Sean de Wolski am 14 Feb. 2012
yup.
But be sure to preallocate to_delete.
Or even better use a logical vector:
to_delete = false(1,1,size(big_data,3));
while ...
to_delete(1,1,index) = true
end
etc

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by