Hi @Elzbieta,
The issue you are encountering likely stems from the way you are checking for the presence of subjects and conditions in your text files. In your current implementation, you are using
find(~cellfun(@isempty,strfind(field,subject{isubject}))==true)
to check for the existence of a subject. If the subject is not found, the loop continues without adding any data to the structure for that subject. To ensure that you capture data for all subjects, consider the following adjustments.
Check for All Subjects: Ensure that your condition checks are comprehensive and correctly structured. You may want to use a more robust method to verify if a subject exists in the file.
Initialize the Structure: Make sure that the structure s is initialized outside the loop and that you are correctly appending data for each subject and condition.
Debugging: Add debugging statements to track which subjects and conditions are being processed. This will help you identify where the logic may be failing.
Here is a refined snippet of your code to illustrate these points:
% Initialize the structure outside the loop s = struct();
for isubject = 1:length(subject) subject_found = any(~cellfun(@isempty, strfind(field, subject{isubject}))); if subject_found for icond = 1:length(condition) condition_found = any(~cellfun(@isempty, strfind(field, condition{icond}))); if condition_found % Determine condition type cond = determineCondition(condition{icond}); % Add data to structure if any(~cellfun(@isempty, strfind(field, freqs{2}))) s.(subject{isubject}).(cond).(freqs{2}) = ecgData; else s.(subject{isubject}).(cond).(freqs{1}) = ecgData; end end end else disp(['Subject ' subject{isubject} ' not found in file.']); end end
function cond = determineCondition(condition) switch condition case {'siedzaca', 'siedzenie'} cond = 'sitting'; case {'chodzenie', 'bieganie', 'truchtanie', 'dreptanie'} cond = 'walking'; otherwise cond = 'unknown'; end end
This approach should help you capture data for all subjects and conditions as intended.
Hope this helps.