NAMING THE FILE TO BE SAVED

Hello, I have a ECG feature extraction algorithm. I want to save the extracted feature matrix as a csv file. I have done it but each time I change the input ECG file, I'll have to change the name of the csv file. Is there a way to automatically change the output filename in accordance with the input name? This is what I've done so far
filename = 'features_100.csv';
T=table(RR_values, amp_Rpeak, QRS_dur , ST_seg);
writetable(T,filename) ;

2 Commenti

Jan
Jan il 2 Mar 2018
And what is the input file name? Please explain, how the file names are related, otherwise it is hard to suggest code to implement this relation.
Jan
Jan il 2 Mar 2018
Modificato: Jan il 2 Mar 2018
Where does the name come from and how do you want to modify it for the output? The question still does not contain enough information to be answered - except I dare to guess, what you want. I guessed again, see [EDITED] in my answer.

Accedi per commentare.

Risposte (1)

Jan
Jan il 2 Mar 2018
Modificato: Jan il 2 Mar 2018
Maybe you want to replace the file extension only:
InFile = 'C:\Data\features_100.ecg';
[Folder, Name] = fileparts(InFileName);
OutFile = fullfile(Folder, [Name, '.csv'])
But this is a guess only.
[EDITED] Perhaps your comment mean, that you have the number 100 or string '100' and want to insert it in the file name:
num = 100;
FileName1 = sprintf('features_%d.csv', num)
str = '100';
FileName1 = sprintf('features_%s.csv', str)
But this is still guessing.

5 Commenti

The infile is also a csv file
X=xlsread('D:\mtech\PROJECT\Database\100\samples_10s.csv');
Okay. Now please clarify your question:
Is there a way to automatically change the output filename in
accordance with the input name?
Yes, I'm convinced that there is a method to change it automatically. To post it, you have to explain at first, how these names are related. For your input file name
'D:\mtech\PROJECT\Database\100\samples_10s.csv'
what is the wanted output file name? Don't you see, that you did not explain yet, what you want to get?
Yeah I see, sorry about that. The record name is actually 100. so the output filename should be something like feature_100 or 100_features etc. So, even when I change the input record to the next one, 101 or 102 or whatever, I'll be able to recognise the output file.
InFile = 'D:\mtech\PROJECT\Database\100\samples_10s.csv'
Parts = strsplit(InFile, '\');
OutFile = fullfile(Folder, ['feature_', Parts{end - 1}, '.csv']);

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by