フィルターのクリア

Read from a text file only characters

4 ビュー (過去 30 日間)
xaroula mav
xaroula mav 2015 年 4 月 11 日
コメント済み: Stephen23 2015 年 4 月 13 日
I have a text file from which i want only to read chars, spaces and /n, no numbers no other Punctuation marks (. , ' , \ e.c) . How can i do this? Text example Provided by 'example ' . See bottom for copyright. Available online at http://www . bla bla. com
So i want A= "Provided by example\n See bottom for copyrightAvailable online at\n httpwww bla bla com\n
How can i get it?? Thanks in advance

回答 (2 件)

dpb
dpb 2015 年 4 月 12 日
I'd probably just read the whole thing as a string and then remove the offending characters...

Stephen23
Stephen23 2015 年 4 月 12 日
Reading data and processing data can be thought of as two quite different paradigms. Read the data simply using fileread and then filter it using isstrprop:
str = fileread(filename);
idx = isstrprop(str,'alpha') | isstrprop(str,'wspace');
out = str(idx);
You should read the isstrprop documentation and pick whatever conditions best match your needs.
>> str = sprintf('This is some\ntext with numbers 2015\nand newlines')
str =
This is some
text with numbers 2015
and newlines
>> idx = isstrprop(str,'alpha') | isstrprop(str,'wspace');
>> str(idx)
ans =
This is some
text with numbers
and newlines
  2 件のコメント
xaroula mav
xaroula mav 2015 年 4 月 13 日
Thanks a lot!!
Stephen23
Stephen23 2015 年 4 月 13 日
My pleasure. You can also Accept answers that help you to resolve your question: this gives points to the people who volunteer their time to help you :)

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

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by