measure distance between mutiple positions without looping

조회 수: 1 (최근 30일)
Matthew
Matthew 2015년 10월 1일
편집: Star Strider 2015년 10월 1일
I have two arrays of XYZ positions data, Spots1 and Spots2. Code below loops though each Spot2 position and measures the distance to each Spots1 subtracted by radius of Spots2.
for vIndex1= 1:size(Spots2,1)
vDist(:,vIndex1) = (sqrt((Spots1(:,1)-Spots2(vIndex1,1)).^2 + (Spots1(:,2)-Spots2(vIndex1,2)).^2))-Radius2(vIndex1);
end
vLimit=min(vDist,[],2);% find minimum value for each row for each dendrite position
vIsClose(vSpotsIndex1) = vLimit < vDistanceLimit;
I am looking for a way to do this without the for loop. My ultimate goal is to find minimum distance measure for each Spots1 position. And if it is less than a set value, to create an array of those spot positions.
There are similar answers, but nothing exactly what i am looking for. Any help would be appreciated. Thank you.

채택된 답변

Star Strider
Star Strider 2015년 10월 1일
편집: Star Strider 2015년 10월 1일
If you have the Statistics Toolbox, the pdist2 function will find the distances.
EDIT — If you don’t have the Stats Toolbox, a loop is the only way to go. You can make your code a bit more efficient with the hypot function.

추가 답변 (1개)

Image Analyst
Image Analyst 2015년 10월 1일
If you have the stats toolbox, try pdist().
  댓글 수: 1
Matthew
Matthew 2015년 10월 1일
I am planning on getting that toolbox, for myself, but I would like to have a way to do it without it. Is it possible?

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

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by