Import .file values
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Ancalagon8
el 5 de Abr. de 2024
Editada: Ancalagon8
el 6 de En. de 2025
I have a .file I need to import the data into matlab, but i have trouble handling the format.
Any help?
0 comentarios
Respuesta aceptada
Voss
el 5 de Abr. de 2024
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 comentarios
Voss
el 7 de Abr. de 2024
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
el 7 de Abr. de 2024
C = regexp(str,'([^\r\n]+)\d{2}{''y'':(.+?), ''x'':(.+?), ''z'':(.+?)} {''a'':(.+?), ''b'':(.+?), ''c'':(.+?)}','tokens');
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Import and Analysis en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!