필터 지우기
필터 지우기

How to replace values in a very large array

조회 수: 5 (최근 30일)
Jonathan Weber
Jonathan Weber 2022년 8월 3일
댓글: Jonathan Weber 2022년 8월 4일
Hi
I have an array idx_Laser which is very large (~1 billion values). Whenever a certain condition is fulfilled for another array tdcRelTime I want to replace the values in my idx_Laser array.
The trivial solution would probably be:
for xx = 1:length(tdcRelTime)
if tdcRelTime(xx) < 1.5e10
idx_Laser(idx_Laser==xx) = 0;
end
end
However, as both arrays are quite big, this takes extremely long.
Is there a solution for that problem that is computionally more efficient?
I thought about iterating only through a part of the idx_Laser array, as this is sorted by the size of the values, but I couldnt come up with a good solution.
  댓글 수: 3
Jonathan Weber
Jonathan Weber 2022년 8월 4일
Hey :)
Thanks for the comment.
Yes I can hold the arrays in memory. But
idx_Laser(ix) = 0;
is not really what I was searching for.
The Problem is in the line
idx_Laser(idx_Laser==xx) = 0;
Because sweeping through that array is what takes so long.
I will take a look at these tall arrays though.
Jonathan Weber
Jonathan Weber 2022년 8월 4일
What I came up with is a bit confused, but the performance is not so bad.
As I mentioned the array idx_Laser is sorted and the longest bin has "noElements" values.
Maybe someone has a better idea:
for zz = 1:length(tdcRelTime)
if tdcRelTime(zz) < 1.5e10
idx = find(idx_Laser == zz, 1);
for xx = idx:idx + noElements
if idx_Laser(xx) == zz
idx_Laser(xx) = NaN;
end
end
end
end

댓글을 달려면 로그인하십시오.

채택된 답변

Mohammad Sami
Mohammad Sami 2022년 8월 4일
You can modify what @dpb suggested as follows.
xx=find(tdcRelTime < 1.5e10);
idx_Laser(ismember(idx_Laser,xx)) = 0;
  댓글 수: 1
Jonathan Weber
Jonathan Weber 2022년 8월 4일
yes, thats much faster than my approach...
Thanks to both of you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by