MATLAB Answers


How to Select a distinct subset of a CellArray

Asked by Léon
on 17 Jun 2013


please consider the following problem:

x = {1,1;1,2;1,3;2,1;2,2}
[C,IA,IC] = unique(x(:,1))
C(1) % ==> is 1, now I want to get all rows of x where we have a 1 in the first column.

Would be super glad to get a tip how to achieve that!



No products are associated with this question.

2 Answers

Answer by David Sanchez
on 17 Jun 2013
v = find(x(:,1)==C(1))


Answer by Andrei Bobrov
on 17 Jun 2013
x = [1,1;1,2;1,3;2,1;2,2];
out = x(x(:,1) == 1,:);


Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!