How to read .txt file with numbers and texts?

8 ビュー (過去 30 日間)
Elaheh
Elaheh 2018 年 4 月 30 日
コメント済み: Walter Roberson 2018 年 5 月 1 日
Hello. I have a .txt file including numbers and texts separated by tabs. I have tried dlmread, csvread, etc but not still able to get the file content as a matrix. I do not know what is wrong. I appreciate your help.
file=strcat('C:\my_files\','1,3','.txt');
SCRIPTfile = char(file);
dataSCRIPT=dlmread(SCRIPTfile);

回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 4 月 30 日
Use readtable(); it will figure everything out automatically.
  14 件のコメント
Elaheh
Elaheh 2018 年 5 月 1 日
This is the script now. SCRIPTfile=strcat('C:\my_files\english experiment\'{1},'1,3','.txt'); if iscell(SCRIPTfile); SCRIPTfile = SCRIPTfile{1}; end fmts = repmat({'%f'}, 1, 11); fmts([2,4, 10]) = {'%[^\t]'}; fmts(11) = {'%*[^\n]'}; fmt = strjoin(fmts,''); fid = fopen(SCRIPTfile, 'rt'); datacell = textscan(fid, fmt, 'HeaderLines', 3, 'Delimiter', '\t'); fclose(fid);
Cell contents reference from a non-cell array object. Error in collectData (line 33) SCRIPTfile=strcat(SCRIPTroot{1},'1,3','.txt');
Walter Roberson
Walter Roberson 2018 年 5 月 1 日
remove the {1} from that line.

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by