Calculate number appearance within a range
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Ancalagon8
il 19 Gen 2023
Modificato: Ancalagon8
il 6 Gen 2025
I need help calculating the number of times a number appears within a range.
0 Commenti
Risposta accettata
Star Strider
il 19 Gen 2023
LD = load(websave('TT','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1268555/TT.mat'));
TT = LD.TT
Edges = [1 2 10 20 50 100];
[BinCounts,Edges,Bin] = histcounts(TT, Edges);
BinCounts
figure
histogram(TT, Edges)
xticks(Edges)
grid
xlim([min(Edges) max(Edges)])
xlabel('Bin Limits')
ylabel('Counts')
Thi histogram plot gives a better depiction of the bin limits than a bar plot of the histcounts results would.
.
11 Commenti
Askic V
il 25 Gen 2023
@Star Strider can you please explain, how you upload file and use load command in th code, just like in the example
load(websave('TT','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1268555/TT.mat'));
Star Strider
il 25 Gen 2023
@Askic V — That is exactly how I do it, although I always load into a output variable so that I have some control over what loads, and so I can change the name of the variable used in the subsequent script if necessary. (Since I rarely use websave, credit for discovering this goes to @Karim, who was appropriately rewarded for discovering it.)
Più risposte (1)
Askic V
il 19 Gen 2023
Perhaps this code snippet will help you:
load TT
classes = [1 2 10 20 50 100];
tol = 1e-10;
res = zeros(size(diff(classes)));
for i = 1:numel(classes)-1
res(i) = sum(TT >= classes(i)-tol & TT < classes(i+1)+tol);
end
res
0 Commenti
Vedere anche
Categorie
Scopri di più su Geographic Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!