How to remove cells that have the same value at the first row, first column as the previous cell, in a cell array?

2 visualizaciones (últimos 30 días)
I have tried the following, being "C1" the original cell array and "C1_no_repeats" the cell array that I want to create by deleting the cells of "C1" that have a similar value at (1,1) as the previous cell of "C1":
for aa=1:size(C1)
if C1{aa}(1,1)==C1{aa+1}(1,1)
C1_no_repeats{aa+1}=[];
else C1_no_repeats{aa+1}=C1{aa+1};
end
end
It didn't work: not only C1_no_repeats{1} is empty, but C1_no_repeats stops after the first cell with repeated (1,1) values (if C1_no_repeats has 100 cells and cell 5 has the same values at (1,1) as cell 4, then C1_no_repeats has only 4 cells...)

Respuestas (1)

David Hill
David Hill el 28 de Feb. de 2022
There is only one repeated value in the example provided. You could round (1,1) values if you want them to be close but not exactly the same.
b=[];
for aa=1:length(indexed_finalf_before2)
b=[b,indexed_finalf_before2{aa}(1,1)];
end
[~,idx]=unique(b,'stable');
no_repeats=indexed_finalf_before2(idx);

Categorías

Más información sobre Data Types en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by