textscan in Matlab when delimiter is in a field and what to ignore " character

∥☆過路亽.° 提交于 2020-01-05 08:00:52

问题


Using textscan I'm trying to read a file that has comma separated data in the following format:

"1234","24.0","Hello, my name is Joe"
"4567","25,0","Hi, I'm Jane"

The non-delimiter comma in the third field are problematic and I ultimately don't want the "" around the pieces of data.

I've tried the following, but it leaves a " on the end of the last field. I can remove this any number of ways, but I find it quite annoying and am sure there is a smarter way. Any ideas?

textscan(fileId, '"%s %s %s', 'Delimiter', {'","'})

Using %s" for the last part of the formatSpec seems natural, but isn't working.


回答1:


you could do this

textscan(fileID,'%q,%q,%q','Delimiter','\n');


来源:https://stackoverflow.com/questions/16242074/textscan-in-matlab-when-delimiter-is-in-a-field-and-what-to-ignore-character

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!