I want to link data points based on ids (which are linked numerically) and then make clusters; finally deriving all the clusters + know each cluster size?

Since I am new to matlab, I am noob on coding; Could some one help me figure out a code when using the ids it would feasible to build clusters and stop when a cluster is built and start a new cluster and so on...
I have attached the input file for your reference.
Thanks in advance
J

 Accepted Answer

filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/734224/Test%20file.xlsx';
T = readtable(filename, 'VariableNamingRule', 'preserve');
ns = T.id; nd = T.id_1;
mask = nd ~= 0;
s = ns(mask); d = nd(mask);
nd = T.id_2;
mask = nd ~= 0;
s = [s; ns(mask)]; d = [d; nd(mask)];
nd = T.id_3;
mask = nd ~= 0;
s = [s; ns(mask)]; d = [d; nd(mask)];
nd = T.id_4;
mask = nd ~= 0;
s = [s; ns(mask)]; d = [d; nd(mask)];
G = graph(s, d);
plot(G)
bins = conncomp(G);
The bins can be analyzed to extract the connected components. At the moment I do not know of any nice way of doing that.

5 Comments

Thanks a ton bro. It works. but Can we plot this in xyz axes and change the colour codes of the cluster.
I am highly grateful for this immense help you gave done to me.
I have attached the file for your kind reference. Thank you Thank you Thank you.
J
There is no xyz data provided in the file, and there is only two "type" entries, not atom names, so we cannot deduce bond angle.
hello walter
The type are the atom names since I am working with C and H atoms only and in the topmost row the x, y and z coordinates of a particular atom (which has been indexed as id) has been provided. d is the value of the calculated diameter of a particular atom from the axis. We do have columns with bond order and charge;
I can attach those values for your reference, if it's ok, with you.
Kind Regards
Anindya
If coordinates are available, then the graph() object plot() method can be told to use them.
I am not sure what you mean about color codes? Do you mean that you want atoms to be colored according to their type, or do you mean that you want each molecule to be a different color than the other molecules ?
Hello Walter
This is the worksheet on which I am working on. I have labelled them appropriately for your reference, the xyz-axes represents the box and diameter from the origin is also calculated.
The coordinates, the bond order values, the charges, the number of bonds and the atom bond order along with its lone pair of elctrons areall given. Is there any code to represent all this information in a plot?
I also want to colour code each molecule/cluster with specific colour. Is there any code for that?
Thank a ton for your time and support.
Regards
J

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!