How do I select some data from a matrix?

조회 수: 4 (최근 30일)
Rita
Rita 2016년 3월 28일
댓글: Rita 2016년 3월 31일
I have for example this matrix
A=[2 0.9;
2 0.8;
2 1.0;
2 0.8;
3 0.3;
3 0.7;
3 0.8;
3 0.7]
I want to have just the first two rows of A in each repetition. The "repetition" is in column 1 of A. Here, the repetition is 2 and 3. So B equals:
B=[2 0.9;
2 0.8;
3 0.3;
3 0.7]
Thanks for help.
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2016년 3월 28일
this is not clear, what kind of repetition? only in in first column?
Rita
Rita 2016년 3월 29일
편집: Image Analyst 2016년 3월 29일
Sorry about that.
I mean column 1 = [2 2 2 3 3 3 3] are repetitions. In my real matrix I have 500 times of data from 2 to 20 and I want to create an matrix with the first 100 times of 2 ,3,4,...20 for the first column and the corresponding values for each row.
I am looking for a function which can make B like this:
B=[A(1:2,:);A(5:7,:)]
I need to extend this for my real data.
Thanks

댓글을 달려면 로그인하십시오.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 3월 28일
[~,ii]=unique(A(:,1),'stable');
jj=sort([ii,ii+1]);
out=A(jj,:)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by