Clear Filters
Clear Filters

How can I make the following for loop faster without exceeding the memory limit?

2 views (last 30 days)
EX.
% remove these indices from faces (really long array)
pt_indices = [1 357 472 10035 ...];
faces = N x 3 matrix (extremely large matrix)
% reverse order so indices to be removed do not change
for i = length(pt_indices):-1:1
sel = faces>pt_indices(i);
faces(sel) = faces(sel) - 1; % adjust face indices
end
I tried to convert the for loop to a matrix operation but it exceeded the memory limit. Is there another way to speed this up?

Accepted Answer

Walter Roberson
Walter Roberson on 27 Nov 2017
[~, binnum] = histc(faces, [pt_indices, inf]);
faces = faces - binnum;

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!