How to read text table with value in scientific notation and column headers?
5 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
KSSV
2017-1-27
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) ;
0 个评论
更多回答(2 个)
Guillaume
2017-1-27
编辑:Guillaume
2017-1-27
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);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Workspace Variables and MAT Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!