How to get all unique positions in a cell array?

1 view (last 30 days)
I have a cell which contains [x, y] values for example
c = cell(1, 0);
c{1} = [1, 1];
c{2} = [1, 1];
c{3} = [2, 1];
c{4} = [2, 2];
c{5} = [2, 2];
c{5} = [2, 3];
c =
1×5 cell array
{[1 1]} {[1 1]} {[2 1]} {[2 2]} {[2 3]}
Is there a way to find all the unique values in an array. so the output would be
c =
1×4 cell array
{[1 1]} {[2 1]} {[2 2]} {[2 3]}
I have tried to use the unique function but that didn't work initally and I can't find any resources to help.
Comment if you need any more information, im still relatively new to using matlab

Accepted Answer

Voss
Voss on 22 Oct 2023
c = num2cell(unique(vertcat(c{:}),'rows'),2);
  3 Comments
Magnus
Magnus on 22 Oct 2023
Hello thanks you very much this worked perfectly

Sign in to comment.

More Answers (0)

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!