MATLAB Answers

I would like to find elements of a matrix that fulfill a condition but after every loop the condition is changing.

1 ビュー (過去 30 日間)
Alex Perrakis
Alex Perrakis 2021 年 9 月 6 日
コメント済み: Walter Roberson 2021 年 9 月 7 日
i have a 428x29 matrix of particle diameters and i would like to sort these diametes in classes beginning from 0.05 to 0.1 μm and ending at 30 μm,so 600 classes, i would like a loop that searchs the matrix and places those elements in another matrix by row. My problem ist that i do not know how i can change the condition after every loop and also how to create a matrix in the form of:
class diameteres
1 ......
2 .....
I know i might ask a lot but i would love some help because i am stack as all hell!.
Thank you very much


Jeff Miller
Jeff Miller 2021 年 9 月 7 日
I think this will almost do what you want.
edges = 0:0.05:30;
[~,~,bin_numbers] = histcounts(diameters,edges);
The output bin_numbers will show, for each diameter, which bin it falls into (what I think you are calling 'class') in your original question. Then, for example, diameters(bin_numbers==1) will be a vector of all of the diameters in the first bin.
In general there might be different numbers of diameters in the different bins, so you might not be able to format the data into a 2d matrix like you show above (i.e., different rows would need different numbers of columns).
  3 件のコメント
Walter Roberson
Walter Roberson 2021 年 9 月 7 日
If you need the count of the number of particles at each size, then
edges = 0:0.05:30;
bin_counts = histcounts(diameters,edges);
and there would be no need to build the cell array that extracts each particle into a bin for that size class.


その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by