How do I read multiple float values in different columns from a txt-File with headers?
Show older comments
So I am trying to build an automatic analysis application for specific sets of data and to that extent I want to read the data from files like the one attached. I've tried a lot using fscanf and also textscan, but somehow nothing seems to work. For example,
fid=fopen('728 v FS.txt','r');
fgetl(fid); fgetl(fid); %used to skip the header lines
A=fscanf(fid,['%f',repmat('%*s',1,24), '%[^\n]'],[2,inf]); %here I tried to read only the first column
fclose(fid);
returned not only the first column as row, but also another one that had the constant value 13.000, which isn't even included in the original file. Consequently, when trying again with something like
fid=fopen('728 v FS.txt','r');
fgetl(fid); fgetl(fid); %used to skip the header lines
A=fscanf(fid,['%f %f %f',repmat('%*s',1,22), '%[^\n]'],[2,inf]); %here I tried to read the first three columns
fclose(fid);
the results were not at all as expected. Furthermore, the first code only gives 4 decimals, whereas I want the whole number to be displayed. That is a problem I also have when using textscan, as columns 2 and 3 lose all their decimals and remain as only integer values, while readtable almost gives the desired result, but still cuts the last decimal in those columns.
I am fairly new to Matlab and even though I have done a little C coding a few years back, you would be absolutely right to call me an amateur. So I'd appreciate a solution for reading the whole float values of columns 1, 2, 3 and 7, even more, however, if that came with an explanation of how to deal with similar problems in the future.
Thanks in advance!
Accepted Answer
More Answers (0)
Categories
Find more on Large Files and Big Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!