How to count values in a script?

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.

답변 (2개)

Star Strider
Star Strider 2016년 1월 17일

0 개 추천

I would use the sum function.

댓글 수: 2

Aci
Aci 2016년 1월 20일
Hi. Thank you for the answer. However, I don't want to know the sum of As, Bs, and Cs because that should equal to 200. I want the script to count it out for me, as the number of As, Bs, and Cs will vary with each iteration. I was wondering if the countcats function can help.
Star Strider
Star Strider 2016년 1월 20일
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
Chad Greene 2016년 1월 20일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Reinforcement Learning Toolbox에 대해 자세히 알아보기

제품

태그

질문:

Aci
2016년 1월 17일

댓글:

2016년 1월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by