reading a txt file including dash
3 ビュー (過去 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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/166325/image.jpeg)
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 );
0 件のコメント
採用された回答
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 Center および File 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!