Hi all,
I have to read the file (inserted in attachment) and only need the numeric portion as a matrix(array). The extension of file is .TXK .
Thanks in advance

 채택된 답변

Turlough Hughes
Turlough Hughes 2020년 3월 4일
편집: Turlough Hughes 2020년 3월 4일

0 개 추천

You could use the readmatrix function as follows:
filename = 'My2.TXK'
opts = detectImportOptions(filename,'FileType','text')
data = readmatrix(filename,opts)
the .TXK extension is not recognised by readmatrix which is why I specified the FileType as text in the import options.
You could optionally read in as a table:
T = readtable(filename,opts)
If you want to get the variable names automatically, for example if you have a number of similar data files, I would need to see what the first line of text looks like generally across the files.

댓글 수: 4

Guillaume
Guillaume 2020년 3월 4일
편집: Guillaume 2020년 3월 4일
Ahmed Anas' comment moved here:
i could not understand the 'detectImportOptions' command.
and getting an error about it
Guillaume
Guillaume 2020년 3월 4일
You haven't indicated which version of matlab you are using. It must be fairly old (<2016b) if it doesn't support detectImportOptions.
Ahmed Anas
Ahmed Anas 2020년 3월 4일
am using 2016a right now..
Ahmed Anas
Ahmed Anas 2020년 3월 4일
Btw it is working fine on 2019b..

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Guillaume
Guillaume 2020년 3월 4일

0 개 추천

Should work in R2016a:
filename = 'My2.TXK'; %using full path would be better
[fid, errmsg] = fopen(filename, 'rt');
assert(fid > 0, 'Failed to open "%s" due to error: %s', filename, errmsg);
data = cell2mat(textscan(fid, '%f%f%f', 'Delimiter', {'\t', ' '}, 'MultipleDelimsAsOne', true, 'HeaderLines', 1));
fclose(fid);

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

릴리스

R2016a

질문:

2020년 3월 4일

답변:

2020년 3월 4일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by