# Is there a function that will allow me to convert a Euclidean distance calculation for two vectors in a matrix to all the vectors in the matrix?

조회 수: 3(최근 30일)
Alexander Eaton 2018년 3월 24일
댓글: Alexander Eaton 2018년 3월 25일
The code I have currently converts any two rows of 4096 image vectors within a matrix which I have named allData. e.g.
diffs = allData(1,:) - allData(2,:) % 1 being the first row of vectors...
diffsSq = diffs .*diffs
sqrt(sum(diffsSq))
Is there a Matlab function that can maintain this calculation and iterate over all the image rows comparing each with each and then allow me to take the average(mean) of the result. I know thats a lot of calculations but hopefully it will make my result more accurate than just comparing distance between two images.
I suppose the mean is just one line of code e.g. result = mean(allData,dist) or something to that effect.
I appreciate any guidance you can share, thank you

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

### 채택된 답변

Von Duesenberg 2018년 3월 25일
If I understand your question correctly, this should do the trick:
mean(pdist(allData))
##### 댓글 수: 3표시숨기기 이전 댓글 수: 2
Alexander Eaton 2018년 3월 25일
sorry if I only upvoted one answer here,dont know how I can do both, they were both very helpful.

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

### 범주

Find more on Matrix Indexing in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!