How to bin a simple number array?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
That One
am 25 Jul. 2016
Kommentiert: Steven Lord
am 26 Jul. 2016
Hello,
I'm reading a simple number array from a .txt file (all integers) using:
fileID = fopen('control.txt','r');
formatSpec = '%d';
A = fscanf(fileID,formatSpec);
Now I want to bin these integers into a several groups:
Group 1: integers from 21 to 100;
Group 2: integers from 101 to 500;
Group 3: integers from 501 to 1000;
Group 4: integers from 1001 to infinity (max number unknown).
I'm also interested in finding the range (how many numbers) of each group.
Thank you!
0 Kommentare
Akzeptierte Antwort
Azzi Abdelmalek
am 25 Jul. 2016
A=1:120
[b,c]=histc(A,[21 50 60 100 inf])
out=accumarray(c'+1,(1:numel(c))',[],@(x) {A(x)})
out=out(2:end)
celldisp(out)
Weitere Antworten (1)
Steven Lord
am 25 Jul. 2016
Use the histcounts function and specify a vector of edges.
4 Kommentare
Star Strider
am 26 Jul. 2016
You have already come close to defining them:
Group 1: integers from 21 to 100;
Group 2: integers from 101 to 500;
Group 3: integers from 501 to 1000;
Group 4: integers from 1001 to infinity (max number unknown).
Use the max function to help you define the upper edge.
Experiment with to get the result you want.
Siehe auch
Kategorien
Mehr zu Matrices and Arrays 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!