Convert *.lvm automatically in *.txt

53 vues (au cours des 30 derniers jours)
Antonia Schelte
Antonia Schelte le 21 Juin 2016
Déplacé(e) : Voss le 27 Fév 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 commentaires
Lina
Lina le 27 Fév 2024
Déplacé(e) : Voss le 27 Fév 2024
How to read lvm or any type of files with different names in loop like ECG1,ECG2,ECG3..... in the same mfile automatic
Voss
Voss le 27 Fév 2024
Déplacé(e) : Voss le 27 Fév 2024

Connectez-vous pour commenter.

Réponses (2)

NE
NE le 23 Juil 2016
Modifié(e) : NE le 24 Août 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 le 24 Août 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.)

Catégories

En savoir plus sur Workspace Variables and MAT-Files dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by