using nchoosek to gather possible combinations of data

3 ビュー (過去 30 日間)
P_L
P_L 2019 年 4 月 16 日
回答済み: KSSV 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 件のコメント
KSSV
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
KSSV 2019 年 4 月 16 日
N = length(x) ;
idx = nchoosek(1:N,2) ;
xi = x(idx) ; yi = y(idx) ; zi = z(idx) ;

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by