フィルターのクリア

Apply script to multiple data files and save specific workspace outputs

1 回表示 (過去 30 日間)
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?

採用された回答

Hrishikesh Borate
Hrishikesh Borate 2021 年 7 月 16 日
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 件のコメント
Ana Gabriela Guedes
Ana Gabriela Guedes 2021 年 7 月 16 日
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'} ?

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImport, Export, and Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by