フィルターのクリア

Reading a textfile without removing leading zeros

20 ビュー (過去 30 日間)
Abhinav
Abhinav 2018 年 2 月 7 日
コメント済み: Star Strider 2018 年 2 月 7 日
I want to read the attached text-file which contains two columns: text and numeric. I used the code:
fileID=fopen('NWISMapperExport.txt','r');
z=textscan(fileID,'%s %f');
fclose(fileID);
The problem is that it removes leading zeros in the second column, is there is a simple way to retain zeros? I had the same problem with importdata.

採用された回答

Star Strider
Star Strider 2018 年 2 月 7 日
If you want to retain the leading zeros, you have to read them in as strings:
filename = 'NWISMapperExport.txt';
fidi = fopen(filename, 'rt');
D = textscan(fidi, '%s%s', 'CollectOutput',1);
Look = D{:}(1:5,2) % Check First Five Rows, Second Column
Look =
5×1 cell array
{'00152020'}
{'00500460'}
{'00501860'}
{'02380002'}
{'02380003'}
  2 件のコメント
Abhinav
Abhinav 2018 年 2 月 7 日
Thanks!
Star Strider
Star Strider 2018 年 2 月 7 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by