Delete value of cell array and shift without just clearing it.

Hi. I have a cell array containing strings that looks something like this:
A = {'A'; 'B'; 'C'; 'D'; '1000'; 'E'; 'F'; 'G'; '1000'; 'H'}
I would like to delete the values '1000' and shift the other cells up one. When I do it using a for loop with an if condition in it, as in
When I code as I would with matrices, I get a cell array like this:
A = {'A'; 'B'; 'C'; 'D'; []; 'E'; 'F'; 'G'; []; 'H'}
but I need one like this:
A = {'A'; 'B'; 'C'; 'D'; 'E'; 'F'; 'G'; 'H'}
as would happen with a matrix.
Thanks in advance for any tips!

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 25일
편집: Azzi Abdelmalek 2013년 9월 25일
A(ismember(A,'1000'))=[];
%or
A(strcmp(A,'1000'))=[] % The fastest
%or
setdiff(A,'1000')

댓글 수: 1

Thanks once again. If it goes on like this, I'm gonna have to give most of the credit for my function to you :)

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by