フィルターのクリア

Counting duplicate cells in a matrix

1 回表示 (過去 30 日間)
Moe
Moe 2014 年 7 月 8 日
コメント済み: Moe 2014 年 7 月 8 日
Hello everyone,
Suppose matrix a is like:
a = [12,28,28,32,32,37,48,72,72,73,73,73,97,100,100,100];
I want matrix b to be like:
b = [1,2,2,3,3,4,5,6,6,7,7,7,8,9,9,9]
Matrix b is repeating duplicate cells in the matrix a
For example:
1 = 12 (repeat, 1)
2 = 28 (repeat, 2)
3 = 32 (repeat, 2)
.
.
.
7 = 73 (repeat, 3)
Can anyone please help me?

採用された回答

John D'Errico
John D'Errico 2014 年 7 月 8 日
編集済み: John D'Errico 2014 年 7 月 8 日
help unique
Look at the latter arguments. For example, try this:
[~,~,b] = unique(a);
  1 件のコメント
Moe
Moe 2014 年 7 月 8 日
It worked! Thanks.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by