Apply script to multiple data files and save specific workspace outputs

2 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Hrishikesh Borate
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
For more information, refer replace.
  1 Commento
Ana Gabriela Guedes
Ana Gabriela Guedes il 16 Lug 2021
Thank you!!
Just 2 more questions:if I can save an image gaven by the script to each file how can I do it?
And if I want to save more than 1 output I just have to add it to new = {'WAVES','mat'} ?

Accedi per commentare.

Più risposte (0)

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!

Translated by