Convert *.lvm automatically in *.txt

56 visualizzazioni (ultimi 30 giorni)
Antonia Schelte
Antonia Schelte il 21 Giu 2016
Spostato: Voss il 27 Feb 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 Commenti
Lina
Lina il 27 Feb 2024
Spostato: Voss il 27 Feb 2024
How to read lvm or any type of files with different names in loop like ECG1,ECG2,ECG3..... in the same mfile automatic

Accedi per commentare.

Risposte (2)

NE
NE il 23 Lug 2016
Modificato: NE il 24 Ago 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 il 24 Ago 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.)

Categorie

Scopri di più su Workspace Variables and MAT-Files in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by