Import .file values
1 回表示 (過去 30 日間)
古いコメントを表示
I have a .file I need to import the data into matlab, but i have trouble handling the format.
Any help?
0 件のコメント
採用された回答
Voss
2024 年 4 月 5 日
unzip file.zip
ls *.file
str = fileread('file.file')
C = regexp(str,'([^\r\n]+)\d{2}{''y'':(.+?), ''x'':(.+?), ''z'':(.+?)}','tokens');
C = vertcat(C{:})
t = strtrim(C(:,1))
yxz = str2double(C(:,2:end))
5 件のコメント
Voss
2024 年 4 月 7 日
The code in my answer uses fileread, so I guess you are trying to run the code in my comment, which is for combining multiple files into one. Since you don't have readlines, try this instead:
unzip file.zip
ls *.file
directory = '.'; % directory where your files are
output_file = 'all_files.file'; % output file to write, containing contents of all files
files = dir(fullfile(directory,'*.file'));
files = fullfile({files.folder},{files.name});
N = numel(files);
C = cell(N,1);
for ii = 1:N
C{ii} = regexprep(fileread(files{ii}),'\r?\n$','');
end
fid = fopen(output_file,'w');
fprintf(fid,'%s\n',strjoin(C,newline()));
fclose(fid);
% check the result for these two files
type(output_file)
Voss
2024 年 4 月 7 日
C = regexp(str,'([^\r\n]+)\d{2}{''y'':(.+?), ''x'':(.+?), ''z'':(.+?)} {''a'':(.+?), ''b'':(.+?), ''c'':(.+?)}','tokens');
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Import and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!