loop to identify new particles
2 次查看(过去 30 天)
显示 更早的评论
I have the particle Id and y coordinates for every particle in my model over 3000s.
My loop currently tells me how many grains in each second have y coordinates <-0.13 and sums this in the variable 'grains'. This loop includes all the grains <-0.13, even if they have already been included in prevoius time steps.
I want the loop to only include new grains to get mass efflux per second that is not cumulative, and I want it to use the particle ID to do this. For example if particle 2 was included in time step 2, do not include in time step 2.
Can anybody help?
ymax = -0.13;
for b = 1:length(particledata)
%save all the rows in the 1st and 6th column (ID and y-coordinates) of each cell as a new variable y
y{b} = particledata{b}(:,[1 6]);
%use the function table2array to turn the format of the data from a table to an array
y_array{b} = table2array(y{b});
%sum the total number of grains with y coordinate <-0.13 in each cell, and save into a new variable 'grains'
grains{b} = sum(y_array{b}(:,2)<ymax);
fprintf('A total of %d grains left the rice pile\n',grains{b});
end
0 个评论
回答(1 个)
Anmol Dhiman
2021-1-28
编辑:Anmol Dhiman
2021-1-28
Hi Chloe,
Assuming you have all the data in an array format. Follow the below instructions
% outside the loop
temp = [];
% Inside the loop after y_array{b} = table2array(y{b}); statement
temp2 = setdiff(y_Array{b}(:,2),temp);
grains{b} = sum(temp2<ymax);
temp = [temp temp2];
Hope it helps
5 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operators and Elementary Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!