finding numbers below a threshold and doing calculations on them

3 visualizaciones (últimos 30 días)
C.G.
C.G. el 13 de Oct. de 2021
Comentada: C.G. el 15 de Oct. de 2021
I have a model of a box filled with particles. I have the velocity and coordinates of each particle in the box. I have divided the box into 4 segments based on coordinates and want to do calculations on the particles in each segment.
I have written a code which tells me how many particles are in each segment in each time step. But I now it to identify which particles are in each segment of the model, and calculate the average velocity per segment based off individual particel velocities.
file = dir('*.csv');
num_files = length(file);
[~, index] = natsort({file.name});
filelist = file(index);
rows = zeros(1, num_files);
for a = 1:num_files
T = table2array(readtable(filelist(a).name)); %read the data into matlab
%sum how many particles are in each of the 4 segments of the model
S1(a) = sum(T(:,4) >0.13); %first segment thresholds
S2(a) = sum(T(:,4)>= 0.115 & T(:,4) <= 0.13); %second segment thresholds
S3(a) = sum(T(:,4)>= 0.1 & T(:,4) <= 0.115); %third segment thresholds
rows(a) = height(T); %record how many rows are in the whole table (e.g. how many total grains in pile)
ResV(a) = sqrt((T(:,2).^2) + (T(:,3).^2) + (T(:,4).^2)); %calculate the resultant velocity of each particle in each time step
end

Respuesta aceptada

Voss
Voss el 13 de Oct. de 2021
idx = T(:,4) > 0.13; % similarly for other thresholds
ResV(a) = mean(sqrt(sum(T(idx,2:4).^2,2)));
In your original code, note that a value of 0.115 in T(:,4) would be counted in S2 and S3 both and note that T(:,1) is not used. I don't know whether these are intentional.
  3 comentarios
Voss
Voss el 14 de Oct. de 2021
Try changing V1 to V1(a) in the line where V1 is used to calculate GT1(a).

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Just for fun en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by