Reading csv files that have mixed string and numbers, with inconsistent columns and rows

I’m having difficulty loading a csv file that contains mixed string and number data, with inconsistent columns and rows. Can anyone help me out? Once the data is loaded into individual cells/arrays, I should be good to go. importdata() only seems to capture half of the data, and I haven't had much luck with textscan(), though maybe I am using it improperly. A simplified example of the data I am processing can be found below.
Thanks!
Example .csv file:
Name,Weight,,Notes about Weight
Matt,165,,
Jim,250,,Jim is 60 pounds overweight
John,170,,

 採用された回答

J. Webster
J. Webster 2016 年 8 月 18 日
I think the way I'd approach this is with something like the following.
fid = fopen('myfile.csv');
myline = fgetl(fid);
while ischar(myline)
C = strsplit(myline,',')
% C now contains a cell array for each line, maybe you can work with that?
myline = fgetl(fid);
end
fclose(fid);

1 件のコメント

Matt C
Matt C 2016 年 9 月 1 日
Once I extended this code for my purposes, it worked beautifully. Thanks, J!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLarge Files and Big Data についてさらに検索

製品

質問済み:

2016 年 8 月 18 日

コメント済み:

2016 年 9 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by