Read numeric data with csvread

1 次查看(过去 30 天)
Daniel
Daniel 2015-2-12
评论: dpb 2015-2-20
Hello,
I got a csv-file that looks like this.
* text here
* more text...
1,20,3,4
2,30,4,5
* text again
3,4,6,7
*text
And so it goes on.
How do I read the csv-file and only get the numeric data. Everything that has a "*" and text after should be disgarded.
Thank you.

采纳的回答

dpb
dpb 2015-2-12
doc textscan % NB: optional 'commentstyle' parameter
  8 个评论
Daniel
Daniel 2015-2-20
编辑:Daniel 2015-2-20
Thank you for your help! It works fine now. So if I had five columns instead of four i would write "1,5". Now I get how it works.
dpb
dpb 2015-2-20
Ayup; it's the silly way C implemented it's format strings ignoring the long-existing pattern used in Fortran wherein there can be a repeat specifier. Just to show they were smarter; the implementers reversed the order of the width field and the conversion type so there's no way to now write a repeat count unambiguously. In Fortran FORMAT it would be 4F8.0; in Matlab which uses C i/o libraries one has to use repmat to double up or write them all explicitly. On the newsgroup am working with a guy at this instant with a 159-column file...writing %f 159 separate times is rather painful as his initial plea noted until one either has the "a-ha!" moment one's self or somebody shows you the trick (S Lord pointed it out to me years ago; I had never thought of repmat for strings for the purpose despite complaining for years. At one time I wrote a mex file that accepted Fortran FORMAT strings and used the Fortran i/o and passed the values back. Unfortunately I lost the source in the retirement move and haven't had the gumption to re-invent it since.
OK, enough geezer stories/griping... :)

请先登录,再进行评论。

更多回答(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