Two vectors to matrix sorted on occurrence

1 回表示 (過去 30 日間)
Mark Laterius
Mark Laterius 2020 年 6 月 3 日
コメント済み: Mark Laterius 2020 年 6 月 4 日
I have a (n x 2) array, with labels in the first column and the hour they occur at in the second column. Labels are for ease of use given as 1, 2, 3, 4, ... and time is given as 1, 2, ..., 24.
So basically every label has a timestamp at the moment, most occur at many different times. Now I would like to create a matrix with labels as rows and number of times they occur at each hour in the colums. I cannot remember what this is called...
E.g. say that I have 6 hours and 5 labels, I want it to look something like this:
x = [2 0 0 1 0 2;
1 0 0 0 2 0;
0 0 0 0 0 0;
2 0 0 0 0 0;
1 2 4 5 6 0]
So label one occurred twice during the hour 1.
  2 件のコメント
KSSV
KSSV 2020 年 6 月 3 日
Show us a snapshopt of how the nx2 array looks like.
Mark Laterius
Mark Laterius 2020 年 6 月 4 日
So an example of the array would be
y = [1, 0;
2, 0;
4, 1;
3, 2;
2, 2;
4, 3]
So first column is number of label and second row is in which hour that label occurred. Hope this answers your question

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

採用された回答

David Hill
David Hill 2020 年 6 月 3 日
labels=5;
hours=6;
x=histcounts2(a(:,1),a(:,2),[labels,hours]);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by