Convert *.lvm automatically in *.txt

40 ビュー (過去 30 日間)
Antonia Schelte
Antonia Schelte 2016 年 6 月 21 日
移動済み: Voss 2024 年 2 月 27 日
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 件のコメント
Lina
Lina 2024 年 2 月 27 日
移動済み: Voss 2024 年 2 月 27 日
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 2024 年 2 月 27 日
移動済み: Voss 2024 年 2 月 27 日

サインインしてコメントする。

回答 (2 件)

NE
NE 2016 年 7 月 23 日
編集済み: NE 2021 年 8 月 24 日
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 2021 年 8 月 24 日
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.)

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT-Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by