How to pull out rows with a unique value in a specified column?

조회 수: 3 (최근 30일)
Louisa Thomas
Louisa Thomas 2017년 10월 24일
답변: Alan Weiss 2017년 10월 24일
I have a matrix variable called 'summed' which is 1330 x 2.
I want to pull out every row of 'summed' that has a unique value in the second column, and store these in a new variable, called 'uniqueVals'
I tried the following line of code:
uniqueVals = summed(:,2) == unique;
Which didn't work, and I am unsure how I should go about doing this?
  댓글 수: 1
per isakson
per isakson 2017년 10월 24일
  • Are summed floating point numbers?
  • Which release of Matlab do you use?

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

채택된 답변

Alan Weiss
Alan Weiss 2017년 10월 24일
Perhaps the following works:
[C,ia] = unique(summed(:,2));
uniqueVals = summed(ia,:);
Alan Weiss
MATLAB mathematical toolbox documentation

추가 답변 (1개)

Louisa Thomas
Louisa Thomas 2017년 10월 24일
the values in summed are integers, and I'm using MATLAB R2015b

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by