reading a txt file including dash

1 次查看(过去 30 天)
Hello,
I have a .txt file and want to read it in Matlab (actually to read the last raw) but I get the following error:
Error using cat Dimensions of matrices being concatenated are not consistent._
Error in cell2mat (line 75) m{n} = cat(2,c{n,:});
Error in STF_v0 (line 52)
final_data = cell2mat(textscan(fileID ,tkn,'delimiter', '\t', 'MultipleDelimsAsOne',true));
I imagine that is due to -- I have in the file. Any idea how I can fix this? The txt file looks like this and I have also attached it to the message.
Thank you
Below is the code I am using.
fileID = fopen(fullFileName);
column_headers = regexp(fgetl(fileID ),'\t+','split');
tkn = repmat('%f',1,numel(column_headers));
final_data = cell2mat(textscan(fileID ,tkn,'delimiter', '\t', 'MultipleDelimsAsOne',true));
fclose(fileID );

采纳的回答

per isakson
per isakson 2017-7-26
One way
fid = fopen( 'DI_WATER.txt' );
cac = textscan( fid, '%f%f%f%f%f%f%f%f' ...
, 'Headerlines',1, 'Delimiter','\t' ...
, 'TreatAsEmpty','--', 'CollectOutput', true );
fclose( fid );
num = cac{1};
inspect result
>> whos num
Name Size Bytes Class Attributes
num 20x8 1280 double
>> num(end,:)
ans =
20.0000 61.0000 2.8975 0.2955 72.0764 72.0830 0.0056 24.5100
>>

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Large 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