reading a txt file including dash

조회 수: 4 (최근 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
>>

추가 답변 (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