필터 지우기
필터 지우기

Large Cell Array Manipulation?

조회 수: 1 (최근 30일)
mfas
mfas 2015년 8월 3일
편집: Cedric 2015년 8월 3일
I have a nx3 matrix in the from:
P=
x1 y1 z1
x2 y2 z2
. . .
. . .
. . .
xn yn zn
I have then used the rangesearch() function to find the points within a radius of 4 of each point in turn:
N=rangesearch(P,P,4)
Each cell in N gives the row numbers of these positions which is within the range.
How can I then manipulate N to contain the x,y,z positions of these points?
I have achieved this using:
for n=1:Natoms
N{n}=P(N{n});
end
however for large n the loop is very time consuming, is there a faster way or a preexisting function?

답변 (2개)

Jan
Jan 2015년 8월 3일
Is N pre-allocated?
M = cell(1, Natoms);
for n = 1:Natoms
M{n} = P(N{n});
end
  댓글 수: 1
mfas
mfas 2015년 8월 3일
편집: mfas 2015년 8월 3일
Yes N is pre-allocated, sorry that wasn't clear in the question. Is there a way of avoiding the loop entirely to achieve the same result?

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


Cedric
Cedric 2015년 8월 3일
편집: Cedric 2015년 8월 3일
The loop is probably not the limiting factor. RANGESEARCH will be much slower than the loop, for almost any number of atoms. Try it in the profiler, type:
profile viewer
in the command window, type the name of your script in the field labeled "Run this code", click on [Start profiling], and you will see the report.
PS: you probably want
M{n} = P(N{n}, :); % or N if you update it instead of creating a new cell array.
in your loop.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by