reading a txt file including dash

3 ビュー (過去 30 日間)
Very Determined
Very Determined 2017 年 7 月 25 日
コメント済み: Very Determined 2017 年 7 月 26 日
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
>>
  1 件のコメント
Very Determined
Very Determined 2017 年 7 月 26 日
Great! Thanks.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLarge 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