Count the same element in a large rows of one column

1 回表示 (過去 30 日間)
Manti  Etekia
Manti Etekia 2019 年 5 月 13 日
編集済み: madhan ravi 2019 年 5 月 13 日
Hello!
I want to count a specific value of matrix in each row of matrix, the size of the matrix is 421 by 1
Thanks
  2 件のコメント
Walter Roberson
Walter Roberson 2019 年 5 月 13 日
Since you only have one column in each row, then the count for each row will be either 0 (the value is not the target) or 1 (the value is the target), so you can just use
YourMatrix == SpecificValue
Manti  Etekia
Manti Etekia 2019 年 5 月 13 日
Walter Roberson thank you, but from then i want to count all those value and output such as:
value of 9 was 67, Sorry i just start programming
Thank you

サインインしてコメントする。

回答 (3 件)

madhan ravi
madhan ravi 2019 年 5 月 13 日
編集済み: madhan ravi 2019 年 5 月 13 日
uniquevalue = 9; % for example
nnz(matrix==uniquevalue)

KSSV
KSSV 2019 年 5 月 13 日
編集済み: KSSV 2019 年 5 月 13 日
idx = matrix==myvalue ; % this wlill give logical indices
T = nnz(idx) ; % this iwll give you total number of values present
id = find(idx) ; % this will give indices/ positions
If you want to know the repeated values. Use unique
[c,ia,ib] = unique(matrix) ;
If you want along woht count the repeated values:
[a,b]=hist(matrix,unique(matrix))

Andrei Bobrov
Andrei Bobrov 2019 年 5 月 13 日
Let A - your vector (421 x 1):
[a,~,c] = unique(A);
out = array2table([a, accumarray(c,1)],'v',{'value','times'});

カテゴリ

Help Center および File ExchangeCode Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by