How to remove cells that have the same value at the first row, first column as the previous cell, in a cell array?
2 ビュー (過去 30 日間)
古いコメントを表示
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...)
2 件のコメント
回答 (1 件)
David Hill
2022 年 2 月 28 日
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);
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!