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

1 view (last 30 days)
Hello,
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 .....
3
4
.
.
.
I know i might ask a lot but i would love some help because i am stack as all hell!.
Thank you very much

Accepted Answer

Jeff Miller
Jeff Miller on 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 Comments
Alex Perrakis
Alex Perrakis on 7 Sep 2021
Edited: Alex Perrakis on 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
x1=0.05;
x2=0.1;
k=1;
for j=1:29; %columns
for i=1:428; %rows
if x2>E_D(i,j,1)& E_D(i,j,1)>x1;
E_D(i,j,:)=B(:,k,:);
end
x2=x2+0.05;
x1=x1+0.05;
end
k=k+1;
end
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 on 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.

Sign in to comment.

More Answers (0)

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!