Loop Question for particle

1 次查看(过去 30 天)
shah nawaz
shah nawaz 2020-5-13
I have following data I want to use first 2 columns in a for loop to detect the particles for which there is no contact. first 2 columns show 2 particles which are in contact. How can I get an output in tabular form. Basically i want to detect those particles for which there is no contact. Particles are 484 and total number of contacts is 956.
1 324 0.720141865396207E+00 0.000000000000000E+00 0 0.000000000000000E+00
1 439 0.940050831127248E+00 0.000000000000000E+00 0 0.000000000000000E+00
1 441 0.131609998985588E+01 0.000000000000000E+00 0 0.000000000000000E+00
2 25 0.363379567116406E+00 -0.000000000000000E+00 0 0.000000000000000E+00
2 89 0.753090369602638E+00 0.000000000000000E+00 0 0.000000000000000E+00
2 109 0.851303474754872E+00 0.000000000000000E+00 0 0.000000000000000E+00
2 220 0.898508917122121E+00 -0.000000000000000E+00 0 0.000000000000000E+00
3 6 0.890341369366110E+00 0.000000000000000E+00 0 0.000000000000000E+00
3 26 0.283864328102457E+00 0.000000000000000E+00 0 0.000000000000000E+00
Data = importdata('dem22.txt');
Particle1 = Data(:,1);
Particle2 = Data(:,2);
number_of_particles = 484
total_contacts = length(Particle1);
Contact = Particle1+Particle2
Table = cell(956,2);
for i = 1:1:ncont;
j = 1:npa;
Contact(ncont,1) = i;
i = i+1;
Contact(ncont,2) = j;
j=j+1;
Table(i,:) = {i j};
fprintf('%d %d\n', Table{i,:});
end
T = table(Contact,npa);
  4 个评论
Geoff Hayes
Geoff Hayes 2020-5-14
I still don't understand how you determine "no contact" particles. Can you illustrate with an example?
shah nawaz
shah nawaz 2020-5-14
I want to determine those particles which are not in column1 and columns2 and count them. total particles 484

请先登录,再进行评论。

回答(1 个)

Reshma Nerella
Reshma Nerella 2020-7-24
Hi,
You can use union and setdiff functions to find out the particles that are not in contact.
Total_Particles - all particles
Particle1 - particles in column 1
Particle2 - particles in column 2
Contacted_Particles=union(Particle1, Particle2 ) - all particles that are in contact
setdiff(Total_Particles,Contacted_Particles) - gives particles that are not in contact.
Total_Particles, Particle1, Particle2 are all arrays with particle numbers

类别

Help CenterFile Exchange 中查找有关 Data Type Identification 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by