How can I remove identical cell entries containing small arrays
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a matlab cell. Each cell entry is containing a relatively small 2xn array of numbers. Some of these arrays are identical and therefor I want to remove the duplicated cell entry. I have found solutions in case I would have strings, string/characters, characters or numbers, but none for whole arrays inside a cell.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/282197/image.jpeg)
(Although shown here, the arrays are not always just twice in the cell.)
3 commentaires
dpb
le 7 Avr 2020
if ismember(A_tmp{i}, A) == 0 %
A_tmp{} is the content of a cell while A is a cell (empty at first but still a cell). cell2mat exists to convert anyways. Not sure what you're trying to do here??? Why the catenation?
Also, ismember returns a logical array, not just a true|false so if content is more than a single element the return is a vector, not a value
all() might be of help here in that regards but I'd still look at converting the cells to arrays, and if want someone to actually try test code, providing them a sample dataset would likely induce a higher likelihood... :)
Réponse acceptée
Stephen23
le 7 Avr 2020
Two efficient loops, no third-party functions:
S = load('example.mat');
C = S.connect_group;
N = numel(C);
X = true(1,N);
for ii = 1:N
for jj = ii+1:N
if isequal(C{ii},C{jj})
X(ii) = false;
break
end
end
end
D = C(X);
Plus de réponses (2)
Birdman
le 7 Avr 2020
The following code should simply do the job for you:
unique(cell2mat(connect_group),'rows')
After this, you can regroup the arrays however you want.
Voir également
Catégories
En savoir plus sur Cell Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!