blanks are not stored in strsplit

2 ビュー (過去 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 Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by