フィルターのクリア

Issue with textread and data file

1 回表示 (過去 30 日間)
Rene
Rene 2013 年 2 月 14 日
Hello,
I have a data file that I am reading into MATLAB using textread. Everything is fine until I encounter this part of the file:
*** BLOCK 3. Current data ***
13 0.02002002 1
0 0.026246719
0.223 0.026246719
0.3514 0.052493438
I am using the command
file_contents = textscan(fid,'%s','delimiter','\n','whitespace','')
Unfortunately, file _contents now has the first line as 130.020020021. Similar story for the other lines. I believe the issue is the tab between the values. For the case where there is just a blank space between the values, there is no issue. How can I modify my textread command (I want to keep everything as a string) so as to capture the tab? Thank you.

採用された回答

Image Analyst
Image Analyst 2013 年 2 月 14 日
Use fgetl() instead of textscan(). That will let you pull out strings line by line.
  2 件のコメント
Rene
Rene 2013 年 2 月 14 日
Thanks. But the reason I am trying to stick with textread is that the code I wrote works fine for the case where the spaces between the entries in the above block are not tabs, but simple spaces obtained by hitting enter a couple of times. Since I don't know a priori which format the data file will have I want to capture both scenarios!
José-Luis
José-Luis 2013 年 2 月 14 日
You could replace tab by spaces before importing to Matlab. In *nix you could use sed otherwise you would need to import line by line and check whether you have tabs or spaces. That could be slow. If you know the exact lines where tabs are expected you could account for that as well.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Data Preparation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by