Remove duplicate cells from cell array of different dimensions

조회 수: 3 (최근 30일)
Tyler
Tyler 2016년 7월 13일
댓글: Azzi Abdelmalek 2016년 7월 13일
Hi,
I have a cell array C of nx1, where each cell contains a vector of different values. Each vector has a different length, ranging from 3 to 8 or so. I would like to output another cell array, where all the duplicate cells in C have been removed. I also don't care about the order of the values within each vector. I suppose I could run a giant for loop (in this case n = 900) where I sort each vector with the cells of C and somehow use that.
I've looked up other similar questions online, but the only answers I've found so far only work if the dimensions of C are constant. My only other guess is that maybe I will have to convert it into an array, where there are Nans for the cells whose vectors are not long enough.
Does someone else spot a solution?
Thanks!

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2016년 7월 13일
A=arrayfun(@(x) randi(10,1,randi([3 8])),1:900,'un',0); % Example
b=cellfun(@(x) sort([x nan(1,8-numel(x))]),A,'un',0)
c=cell2mat(b'')
[~,jj]=unique(c,'rows');
B=A(jj)
  댓글 수: 2
Tyler
Tyler 2016년 7월 13일
Sorry, this does not work when I try it. B outputs a single cell of the first cell of A.
While I don't understand every step, one problem might be that the Nans seem to disappear between b and c. c appears to be a long vector, when it was intended to be an array in order to use unique along the rows...
Azzi Abdelmalek
Azzi Abdelmalek 2016년 7월 13일
You can post a short example and explain what you want

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by