Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Why are some cells not removed in an array?
1 回表示 (過去 30 日間)
古いコメントを表示
Hello,
I need to remove some cells from an array to keep every cells of the same size. I have used this loop for the moment:
iter=1;
while iter<size(DL,2)
if cellfun(@(x) numel(x), DL(:,iter))~=41
DL(:,iter)= [];
indexsuppr=indexsuppr+1; %nb of deleted columns
end
iter=iter+1;
end
DL is a 1X47 cell array at the beginning. Some cells are 1X41 size, some are 1X24. I want to keep only the ones of 1X41. For a reason I don't understand, some 1X24 are deleted but some stay at the end of the loop (from the 24th iteration). Has somebody an idea why? thx in advance!
1 件のコメント
Adam
2017 年 4 月 12 日
Never delete elements of an array while iterating forward through it. You are pulling the rug out from under your own feet.
Iterate backwards for deletion or, better, just find the indices of the elements to delete and then delete them all in one simple instruction rather than doing the deletion within a loop.
回答 (1 件)
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!