# using nchoosek to gather possible combinations of data

1 次查看（过去 30 天）
P_L 2019-4-16

Hi there ,
I am trying to use 'nchoosek' for the data that i have that contains 15 sets of x,y,z coordinates. I want to find all possible pairs of coordinates (x,y and z) data as described in my script.
This is the code I have but I am not sure how to correct my code so I get 105 combinations and not 14190 x 3 which is what the nchoosek function is currently giving me.
As you can see I initially had my x,y,z in seperate vectors but didn'ty know how to use the function with all 3 data. I then tried making a matrix which the function rejected. I finally made the 'dat' vector by combining all the x,y,z vctors into one.
In my script nchoosek is told to take 3 at a time because the order of the 'dat' vector is x1 co-ordinate, y1 co-ordinate, z1 co-ordinate ... xn co-ordinate, yn co-ordinate, zn co-ordinate.
Any help would be much appreciated !!
% script to caluclate the correlation dimension of points
% with delta[log N_D (R)] / delta (log R) ( taken from Kagan.Y (2007)
% Earthquake spacial distribution: The correlation dimension.
% here
% D = dimensionality = 3-D
% N = total number of earthquake pairs = n(n-1)/2
% R = distance between points = sqrt((x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2)
N = 15*(15-1)/2 %the number of pairs I can have
% The Data set (15 points)
x_vals=[-9.33203 -9.92969 -9.40234 -9.47266 -8.83984 -9.50781 -10.0703 -9.08594 -9.50781 -10.0352 -9.12109 -9.05078 -9.26172 -9.82422 -10.3516];
y_vals=[27.8633 27.6172 27.6523 27.5117 27.9336 27.6172 27.3359 27.6172 27.6172 27.2305 27.9336 28.0039 27.793 27.7227 26.7734];
z_vals=[10.0098 8.04297 8.97461 7.98086 9.51289 8.04297 10.1133 10.0305 7.96016 7.98086 9.47148 7.77383 8.76758 9.34727 7.79453];
dat=[-9.33203 27.8633 10.0098 -9.92969 27.6172 8.04297 -9.40234 27.6523 8.97461 -9.47266 27.5117 7.98086 -8.83984 27.9336 9.51289 -9.50781 27.6172 8.04297 -10.0703 27.3359 10.1133 -9.08594 27.6172 10.0305 -9.50781 27.6172 7.96016 -10.0352 27.2305 7.98086 -9.12109 27.9336 9.47148 -9.05078 28.0039 7.77383 -9.26172 27.793 8.76758 -9.82422 27.7227 9.34727 -10.3516 26.7734 7.79453]
k=nchoosek(dat,3)
##### 1 个评论显示 -1更早的评论隐藏 -1更早的评论
KSSV 2019-4-16
YOu have already asked this question and a discussion is going on there.......without closing the existing question it is not fair to open a new question which is as same as your previous question.

### 采纳的回答

KSSV 2019-4-16
N = length(x) ;
idx = nchoosek(1:N,2) ;
xi = x(idx) ; yi = y(idx) ; zi = z(idx) ;

### 类别

Help CenterFile Exchange 中查找有关 Direction of Arrival Estimation 的更多信息

### Community Treasure Hunt

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

Start Hunting!

Translated by