How to make array with first values of matrix

5 ビュー (過去 30 日間)
Filip Konecny
Filip Konecny 2018 年 2 月 22 日
コメント済み: Jan 2018 年 2 月 22 日
Hello to all,
I have a matrix for example like this: [1 2 3 4 5 6 7 8 9 10;2 2 3 3 4 5 5 2 3 3]' the first column represents time, the second ID of time. I need to make a cycle which goes through the matrix and takes the first time value from the group of ID of time.
So in this case the result will be: [1 3 5 6 8 9].
unique function is unfortunately not helpful in this case because the groups of ID of time might repeat.
Thank you very much
Filip

回答 (1 件)

C.J. Harris
C.J. Harris 2018 年 2 月 22 日
% Input
A = [1 2 3 4 5 6 7 8 9 10;2 2 3 3 4 5 5 2 3 3]';
% Result
B = A([boolean(1); diff(A(:,2))~=0],1);
  1 件のコメント
Jan
Jan 2018 年 2 月 22 日
Use true instead of boolean(1).

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by