How to count values in a script?
Mostra commenti meno recenti
Hi. I am writing a script in which agents (say 200 agents) make 3 decisions: A, B, and C. Now, I want to be able to find out how many As, Bs, and Cs are there. How do I do this? Thank you.
Risposte (2)
Star Strider
il 17 Gen 2016
0 voti
I would use the sum function.
2 Commenti
Aci
il 20 Gen 2016
Star Strider
il 20 Gen 2016
My pleasure.
If they are in a matrix, perhaps (Nx3) with a different columns for ‘A’, ‘B’, and ‘C’ (which is likely how I would do it), then sum will sum each column (or row, if you ask it to). Without knowing how your data are organised, it’s difficult to provide an exact solution.
Chad Greene
il 20 Gen 2016
You can indeed use sum if you design your script for it. I'm gonna simplify the problem and consider this case with three agents and two choices:
% Give each agent a number, 1 through 3:
agent = 1:3;
If Agent 1 chooses A and B, Agent 2 chooses A only and Agent 3 chooses B only:
A = [1 1 0];
B = [1 0 1];
What's the total number of agents who chose A?
sum(A)
= 2
Categorie
Scopri di più su Reinforcement Learning Toolbox in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!