Hi Elzbieta,
To include additional information such as the number of patients, number of devices, and external conditions in the concatenated signal matrix, you will need to modify the code to extract and append this information to the data matrix. Assuming that this information is available in the filenames or can be extracted from the files, here is an updated version of your code:
names = {'Alessandra', 'Alfredo', 'Carla', 'Giulia'};
for i = 1: length(names)
filePattern = fullfile(myFolder, ['*', names{i}, '*trial*ECG*data.mat']);
theFiles = dir(filePattern);
data = [];
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
new_data = load(fullFileName, '-ascii');
% Extract information from filename
tokens = regexp(baseFileName, 'patient(\d+)_device(\d+)_condition(\w+)_trial_ECG_data.mat', 'tokens');
if ~isempty(tokens)
patientNumber = str2double(tokens{1}{1});
deviceNumber = str2double(tokens{1}{2});
externalCondition = tokens{1}{3};
else
patientNumber = NaN;
deviceNumber = NaN;
externalCondition = 'Unknown';
end
% Convert condition to numeric
conditionMap = containers.Map({'conditionA', 'conditionB', 'conditionC'}, [1, 2, 3]);
conditionNumeric = conditionMap(externalCondition);
% Append information
numRows = size(new_data, 1);
additionalInfo = repmat([patientNumber, deviceNumber, conditionNumeric], numRows, 1);
new_data = [new_data, additionalInfo];
% Concatenate data
data = [data; new_data];
end
outFullFileName = fullfile(myFolder, [names{i}, '_trial_ECG_data.txt']);
save(outFullFileName, 'data', '-tabs', '-ascii');
end
Changes made:
- Extract Additional Information: Using regexp to extract the number of patients, number of devices, and external conditions from the filename.
- Convert External Condition to Numeric: Using a containers.Map to map external condition strings to numeric values.
- Append Additional Information: Adding the extracted information to each row of the data matrix before concatenation.
I hope this helps!
