Convert *.lvm automatically in *.txt

60 visualizaciones (últimos 30 días)
Antonia Schelte
Antonia Schelte el 21 de Jun. de 2016
Movida: Voss el 27 de Feb. de 2024
Hi. How can I automatically convert in a loop 25 files like A_12.lvm, A_13.lvm, etc. until A_36.lvm with *.lvm extention into *.txt extention ?
Many thanks for help.
  2 comentarios
Lina
Lina el 27 de Feb. de 2024
Movida: Voss el 27 de Feb. de 2024
How to read lvm or any type of files with different names in loop like ECG1,ECG2,ECG3..... in the same mfile automatic

Iniciar sesión para comentar.

Respuestas (2)

NE
NE el 23 de Jul. de 2016
Editada: NE el 24 de Ag. de 2021
Hi,
Is there some .lvm files you don't want to convert ? And by convert do you mean only changing the extension ?
If yes here is something you can try (it convert all the .lvm files that begin with "A_" in a designated folder):
% Ask the user for the folder containing the LVM files
LVM_files_path = uigetdir(cd,'Select the FOLDER of the LVM files to rename');
% Or put the path directly in Matlab (you will need to uncomment the line)
%LVM_files_path = '.....';
% Get all LVM files in the selected folder
LVM_files = dir(fullfile(LVM_files_path,'*.lvm'));
% Loop on all the files
cpt_files_renamed = 0; % init
for id = 1:length(LVM_files)
% Get only the file name
[~,name,~]= fileparts(LVM_files(id).name);
if strcmp(name(1:2),'A_') % Check if the name of the file begins w/ "A_"
num = str2double(name(3:end));
if ~isnan(num)
% rename (the only solution is to use "movefile")
movefile(LVM_files(id).name, [name '.txt']);
cpt_files_renamed = cpt_files_renamed + 1;
end
end
end
% display a message to say that the files have been renamed
msgbox([num2str(cpt_files_renamed) ' files renamed'],'Success');

Walter Roberson
Walter Roberson el 24 de Ag. de 2021
for K = 1 : 36
basename = sprintf('A_%d', K);
filename = [basename '.lvm'];
outfile = [basename '.mat'];
clear data
data.(basename) = lvm_import(filename, 1);
save(outfile, '-struct', 'data');
end
This code saves the data in a .mat file named the same thing as the input file (without the extension), as a variable with the same name as the input file (without an extension.)

Categorías

Más información sobre Data Type Conversion 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!

Translated by