How to read text table with value in scientific notation and column headers?

4 views (last 30 days)
Hello all,
I have a text file (in attachment) made of columns with column headers and scientific notation values. I would like to extract only the numeric content from each column, and keep the data from each column in different variables. I have tried to extract the content with the 'readtable' function, using different options but always without success. I suspect one of the problems might be because of the fact that the data is originally stored in scientific notation (which I cannot avoid). Can anybody help me, please?
Thank you very much. Regards, Pedro Ochoa

Accepted Answer

KSSV
KSSV on 27 Jan 2017
data = importdata('NEW_Val_2_Trial_3_Run_1_UTdata.txt') ;
num_data = data.data ;
X = num_data(:,1) ;
data1 = num_data(:,2) ;
data2 = num_data(:,3) ; % like wise other data's
plot(X,data1) ;

More Answers (2)

Guillaume
Guillaume on 27 Jan 2017
Edited: Guillaume on 27 Jan 2017
The problem with readtable is nothing to do with scientific notation. Matlab copes with that with no problem. The problem is that your file contains two tables, the second one starting at line 15008.
Note that KSSV's answer that you've accepted only loads the first of these tables. Values from line 15008 to 30018 are not loaded.
Here is a way to read the whole file (ignoring headers):
fid = fopen('NEW_Val_2_Trial_3_Run_1_UTdata.txt', 'rt');
matrices = {}; %cell array that will hold all the matrices in your file
while ~feof(fid);
currentmat = cell2mat(textscan(fid, repmat('%f', 1, 7)));
if isempty(currentmat)
fgetl(fid);
else
matrices{end+1} = currentmat; %#OK<AGROW>
end
end
fclose(fid);

Pedro Andre Viegas Ochoa de Carvalho
Hello KSSV,
Your answer solves my problem.
Thank you very much. Regards, Pedro

Community Treasure Hunt

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

Start Hunting!