finding numbers below a threshold and doing calculations on them

2 ビュー (過去 30 日間)
C.G.
C.G. 2021 年 10 月 13 日
コメント済み: C.G. 2021 年 10 月 15 日
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

採用された回答

Voss
Voss 2021 年 10 月 13 日
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 件のコメント
Voss
Voss 2021 年 10 月 14 日
Try changing V1 to V1(a) in the line where V1 is used to calculate GT1(a).
C.G.
C.G. 2021 年 10 月 15 日
Thank you for your help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeJust for fun についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by