plot bar graph based on element type in matrix
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have a 20x100 (t,N) matrix with each element being either 1, 2, or 3. I want to create a bar graph showing the amount of each type of element. so at t=20, of the 100 columns, how many have 1, how many have 2, how many have 3.
Is that possible?
0 Commenti
Risposta accettata
Star Strider
il 7 Ott 2024
Modificato: Star Strider
il 7 Ott 2024
Do you want all of them, or just the last row (t=10)?
This does both —
A = randi(3, 20, 100)
TallyAll = accumarray(A(:), 1)
ResultAll = table(TallyAll, 'RowNames',compose('%d',1:3))
figure
bar(1:3, TallyAll)
Tally20 = accumarray(A(20,:).', 1)
Result20 = table(Tally20, 'RowNames',compose('%d',1:3))
figure
bar(1:3, Tally20)
.
8 Commenti
Più risposte (1)
dpb
il 7 Ott 2024
M=randi([1 3],20,100);
whos t
[min(M(:)) max(M(:))]
histogram(M(20,:))
xticks(1:3)
xlabel('Bin'), ylabel('Count')
title('Counts for t=20')
Vedere anche
Categorie
Scopri di più su Graph and Network Algorithms 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!