How to count number of states in array?

조회 수: 2 (최근 30일)
AbuYusuf
AbuYusuf 2017년 6월 3일
댓글: AbuYusuf 2017년 6월 5일
Hi,
I want to count number of states in vector, each number represent a state: Ex.
A = [1;1;0;1;0]
B = [2;2;1;0;1]
C = [1;1;1;1;1]
A has two states 1 and 0 ==> k=2, B has three states 1, 2, 0 ==> k=3, and C has zero state ==> k=0. how can I write a proforma to define k (number of states)?
  댓글 수: 3
Walter Roberson
Walter Roberson 2017년 6월 4일
If necessary, my suggestion could be followed by testing if the result was 1, and if so then change it to 0.
AbuYusuf
AbuYusuf 2017년 6월 5일
you are right Les, I made a mistake in my question. For C, it should be one state.
I was looking exactly to the line of code which Wlater suggested. Thanks both for your comments.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2017년 6월 3일
length(unique(TheVector))

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by