Reading a textfile without removing leading zeros

8 次查看(过去 30 天)
I want to read the attached text-file which contains two columns: text and numeric. I used the code:
z=textscan(fileID,'%s %f');
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

更多回答(0 个)


Help CenterFile Exchange 中查找有关 Data Import and Export 的更多信息



Community Treasure Hunt

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

Start Hunting!

Translated by