How to make an array with specific matrix values
13 次查看(过去 30 天)
显示 更早的评论
Hello,
I have a matrix for example like this:
[1 2 3 4 5 6 7 8 9 10;
2 2 3 3 4 4 3 3 2 2]
The first column represents time, the second ID of time. I need to make an array where there is first time value from the first group of ID of time for each groups!. So the result looks like this: [1 3 5 7 9] Unfortunately unique function is not helpful in this case.
Thank you
1 个评论
Jan
2018-2-22
Do not post multiple threads for one problem. See https://www.mathworks.com/matlabcentral/answers/384215-how-to-make-array-with-first-values-of-matrix
采纳的回答
更多回答(2 个)
KL
2018-2-22
I assume you have a matrix of two columns,
A = [1 2 3 4 5 6 7 8 9 10;2 2 3 3 4 4 3 3 2 2]';
A(diff(A(:,2))==0,1)
ans =
1
3
5
7
9
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!