How to remove a pattern in a table column
    조회 수: 10 (최근 30일)
  
       이전 댓글 표시
    
Hi,
I have a table with a column. The column looks like this: 'AB_Off' 'ABC' 'CDE_Off'
I would like to remove the '_Off' from every cell in that column. I tried TF = endsWith, and match, but I always get error. "Error using string string is obsolete and will be discontinued. Use char instead." I don't know how to resolve this. Would you please help? Thanks,
Jennifer
댓글 수: 0
채택된 답변
추가 답변 (2개)
  Hamid Ebrahimi Orimi
 2016년 10월 4일
        you mean you have a cell which has 'ABC_Off' string in each element? If I understood correctly, the answer is as follow: A={'ABC_Off', 'ABC_Off','ABC_Off'} for i=1:length(A) if A{i}=='ABC_Off' A{i}='ABC'; end end A is your defined cell.
댓글 수: 0
  elias GR
      
 2016년 10월 4일
        
      편집: elias GR
      
 2016년 10월 4일
  
      strfind function is what you need ( https://www.mathworks.com/help/matlab/ref/strfind.html ). I suppose that you have a cell array of string. Then a simple general solution to remove the _Off from the end of the strings (we suppose that _Off only occurs at the end) is:
str={'AB_Off','ABC','CDE_Off'};
for i=1:length(str)
    ind=strfind(str{i},'_Off');
    if ~isempty(ind)
        str{i}=str{i}(1:ind-1);
    end
end
참고 항목
카테고리
				Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
			
	제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


