Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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

Akzeptierte Antwort

Jeff Miller
Jeff Miller am 7 Sep. 2021
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 Kommentare
Alex Perrakis
Alex Perrakis am 7 Sep. 2021
Bearbeitet: Alex Perrakis am 7 Sep. 2021
That's the point, that different rows need different number of columns because i will need a particle size distribution, so how many particles of each size are there .
i thought something like
for j=1:29; %columns
for i=1:428; %rows
if x2>E_D(i,j,1)& E_D(i,j,1)>x1;
So this would be a loop that searches the columns per prow and if the element of the first sheet of a 3d matrix fulfills the condition it would place elements of the cells of both sheets in another 3D matrix, maybe that could be a different matrix each time. The fact that i need to sort both sheets of the 3d matrix became apparent to me after i posted the question. do you think that would work? thanks for the help again guys!
Walter Roberson
Walter Roberson am 7 Sep. 2021
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)


Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by