How to delete symmetry cells in Matlab?

조회 수: 2 (최근 30일)
NHJ
NHJ 2022년 8월 21일
댓글: NHJ 2022년 8월 23일
Is it possible to delete a symmetry cells? For example I have three cells F{1},F{2} and F{3}. Let say there is another cells in cell number 2 (also in cell number 3), F{2} with size (1x16) cells. I want to delete cell 9 to 16 and remain only cell 1 to 8. How to do that?
for kk = 1:numel(F) % Total 3 cells
for ii = numel(F{kk}) % Total element in second cell
for jj = ceil(ii/2) % center
for oo = jj+1:ii % from cell 9-16
F{kk}(oo) = []
break
end
end
end
end
F{:}
I try to use the same code as I ask in the previous question, but the output is not as expected. Thank you in advance

답변 (1개)

Simon Chan
Simon Chan 2022년 8월 21일
Try this:
F = cell(1,3);
F{1} = cell(1,10);
F{2} = cell(1,16);
F{3} = cell(1,16);
F
F = 1×3 cell array
{1×10 cell} {1×16 cell} {1×16 cell}
F{2}(9:16)=[]
F = 1×3 cell array
{1×10 cell} {1×8 cell} {1×16 cell}
  댓글 수: 2
NHJ
NHJ 2022년 8월 21일
Hi Simon Chan, thank you for your reply. I want the number to be a variable, not fixed. Is it possible?
NHJ
NHJ 2022년 8월 23일
I get the output using the following codes.
for kk = 1:numel(C)
for ii = numel(C{kk}):-1:((numel(C{kk}))/2)+1 % delete cell from C{kk} until ??
for jj = 1:ii-1
C{kk}(jj) = [];
break
end
end
end
Maybe the codes are not efficient but at least the output is as expected.

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by