How to read this file in MATLAB?
25 ビュー (過去 30 日間)
古いコメントを表示
I want to access the data in a file. The file is a TextEdit Document that appears to be unsupported. How do I do this? When I input fileID = fopen(filename,'r'), the command returns 3. I guess I will need to convert the file and then read it, but how?
6 件のコメント
Star Strider
2022 年 3 月 28 日
The readtable function is able to read it. There are two non-empty entries in ‘Var8’ and ‘Var9’ that may be non-printable characters.
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/943824/test.trj.txt', 'VariableNamingRule','preserve')
Vars_8_9_Info = [nnz(~isempty(T1.Var8)); nnz(~isempty(T1.Var9))]
Var_8_Content = cellfun(@double,T1.Var8(~isempty(T1.Var8),:), 'Unif',0);
Var_9_Content = cellfun(@double,T1.Var9(~isempty(T1.Var9),:), 'Unif',0);
.
Mathieu NOE
2022 年 3 月 28 日
hi
if you simply want a numerical array you can use also readmatrix
out = readmatrix('test.trj.txt' ,"NumHeaderLines", 9)
回答 (2 件)
Stephen23
2022 年 3 月 29 日
編集済み: Stephen23
2022 年 3 月 29 日
"I guess I will need to convert the file and then read it, but how?"
Why do you "guess" that? READTABLE has no problem importing the file data:
copyfile('test.trj.txt','test.trj') % just for this forum
fnm = 'test.trj';
opt = detectImportOptions(fnm, 'filetype','delimitedtext', 'NumHeaderLines',9, 'ExpectedNumVariables',7);
tbl = readtable(fnm,opt);
tbl.Properties.VariableNames = {'id','type','mol','x','y','z','bP'}
2 件のコメント
Stephen23
2022 年 4 月 2 日
編集済み: Stephen23
2022 年 4 月 2 日
"copyfile isn't ideal because the files are huge"
COPYFILE is, exactly as I wrote in my answer, just for this forum. Of course you do NOT need to use COPYFILE.
I just used it to get around the restricted file extensions that this forum supports. Another approach would have been to zip it up and then use UNZIP... but would you need to do that with your file? NO. Of course you use your file.
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!