필터 지우기
필터 지우기

How to remove cells that look seemingly like newline character from cell array?

조회 수: 10 (최근 30일)
Dear all, I am involved in a task of analyzing and processing txt file. After converting the txt file line by line into cells, I came across characters which I personally think is newline character. A snippet of the cell output into the command window looks like the pic below:
My goal is to remove the empty lines, which are displayed here as cells containing solely the left arrow sign. I would like to remove these without resorting to loops, as I wrote one already that works fine but can be improved in terms of performance. To do so, I have made the following trials:
Dataset(strcmp(Dataset,newline))=[];
Dataset(strcmp(Dataset,[]))=[];
Dataset(strcmp(Dataset,'←'))=[];
I think I am on the right track, but wonder why they all failed to do the job. Thanks!

채택된 답변

Fangjun Jiang
Fangjun Jiang 2018년 5월 3일
편집: Fangjun Jiang 2018년 5월 3일
It might not be new line. Use double() and char() to do the match.
double(Dataset{3}) to find out the value of the character, then use char() to specify that character.
Dataset(strcmp(Dataset,Char(TheValueAbove)))=[]
  댓글 수: 1
Bohan Liu
Bohan Liu 2018년 5월 3일
Strangely enough, the character in question and newline took on the same look when output into the command window. This is why I was tempted to think that they were the same. In fact, newline=char(10) and my character=char(13). Anyway thanks for the answer.

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

추가 답변 (1개)

Julian Hapke
Julian Hapke 2018년 5월 3일
You should determine which character you are seeing:
Extract a cell that contains only the character in question and convert it to double. Then use the command you already wrote to delete the cells that only contain that character.
You could also provide an example text file, so people can check themselves with what you are dealing.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by