필터 지우기
필터 지우기

blanks are not stored in strsplit

조회 수: 10 (최근 30일)
Leon
Leon 2014년 4월 21일
댓글: Leon 2014년 4월 21일
Below are two lines of my csv file
L1 = 6,ABC,test,22.6
L2 = 7,ABC,,22.6
I am hoping to get the third element of each line, i.e., 'test' for Line 1 and a blank space '' for Line 2.This is my code:
C = strsplit(L,',');
C{3}
But instead, I got 'test' for Line 1, and '22.6' for Line 2. How should I modify the code to get the former?
Thanks.

채택된 답변

Ken Atwell
Ken Atwell 2014년 4월 21일
Set 'CollapseDelimiters' to false to get the behavior you want:
>> C = strsplit('7,ABC,,22.6',',', 'CollapseDelimiters', false)
  댓글 수: 1
Leon
Leon 2014년 4월 21일
It works! Thank you so much for the quick help.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by