Apply script to multiple data files and save specific workspace outputs
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Ana Gabriela Guedes
il 13 Lug 2021
Commentato: Ana Gabriela Guedes
il 16 Lug 2021
Hi!
I have a script to analyse ECG that I run and gives me multiple outputs, from which I want to save a specific one with a specific name.
So, I run the script, that starts loading the data file like this, for example:
%::::::::::::::::::::::::::::::::::::::::::::::::::::: Path Initialization
rootCV=[char(pwd) '\'];
ecgPathConfig(rootCV);
display =0;
% maximise =OPTION.M;
% default=0;
% datPath = [rootCV 'ECG_DAT\MIT\' ]; % path
% datFile = 'cu01.dat'; % file name
%==========================================================================
%::::::::::::::::::::::::::::::::::::::::::::::::::: Load and PreProcessing
%
%¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ Data File
signal = load('EKG_AB16_D1.txt'); %Example of the name of a file
DAT.Path = 'C:\Users\myPath';
DAT.File = 'EKG_AB16_D1.txt';
DAT.Format = 0; DAT.Samp = 500; DAT.Ini = 1; DAT.ECG = signal;
%From here there is the code itself
It will gives me multiple outputs and I want to save a struct named WAVES with the name WAVES_AB16_D1.
The thing is that I have a lot of participants I want to analyse. The .txt files have always the following name format:
EKG_AB16_D1.txt , EKG_AB16_D2.txt, EKG_AB16_G1.txt, EKG_AB16_G2.txt, EKG_AB17_D1.txt, EKG_AB17_D2.txt, EKG_AB17_G1.txt, EKG_AB17_G2.txt , etc
So I want to save the correspondent data file WAVES with the name of the partipant in the front. Is it possible to do this all at once or I have to do it manually?
0 Commenti
Risposta accettata
Hrishikesh Borate
il 16 Lug 2021
Hi,
Assuming that the EKG_AB16_D1.txt, EKG_AB16_D2.txt, etc. files are stored in a directory called inputData, following code demonstrates loading these files and saving the output in the desired format.
inputDataPath = fullfile(pwd,'inputData');
inputDataFiles = dir(fullfile(inputDataPath, '*.txt'));
for i=1:length(inputDataFiles)
signal = load(fullfile(inputDataFiles(i).folder, inputDataFiles(i).name));
% Perform processing on the signal
old = {'EKG','txt'};
new = {'WAVES','mat'};
outputFileName = replace(inputDataFiles(i).name,old,new);
save(outputFileName, 'WAVES');
end
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Data Import and Analysis 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!