concatenation of trigger information for stimulus of interest

1 次查看(过去 30 天)
I want to concatenate information from triggers for each of my critical stimuli and create a new variable which contains the concatenated information. The critical stimuli have been given the number 111. I cannot seem to be able to:
i. identify the event which contains the stimulus of interest
ii. identify the triggers´ info
iii. create a new variable with the concatenated information
I have tried running the following code:
for i = 1:length(EEG.event)
if str2num(EEG.event(i).type) == 111
condition = EEG.event(i-3).type;
sent_version = EEG.event(i-2).type;
item_nb = EEG.event(i-1).type;
new_trigger = ['0' num2str(condition) num2str(sent_version) num2str(item_nb)];
EEG.event(i).type = new_trigger;
EEG.event(i).condition = condition;
EEG.event(i).sent_version = sent_version;
EEG.event(i).item_nb = item_nb;
EEG = eeg_checkset( EEG );
EEG = eeg_checkset( EEG );
end
end
However, the "new_trigger" variable is not generated and I get an error message when I try printing it due to the fact that the variable does not exist.
How could I resolve these issues?
I appreciate your help!

回答(1 个)

Vatsal
Vatsal 2024-1-29
Hi,
It seems that you are trying to create a new trigger by concatenating the types of the previous three events whenever you encounter an event of type 111.
The error may originate from the fact that the “type” field within the EEG.event structure is not a character vector or string scalar, which is necessary for the “str2num” function to operate correctly. This issue could arise if the "type" is already in a numeric format or possibly in a different format altogether.
To diagnose the problem, I created data in the following format to see what error might be produced by the provided code:
EEG = struct();
% Define the event types as a cell array of strings
event_types = {'108', '109', '110', '111', '112', '113', '114', '111', '116', '117', '111'};
% Use a for loop to assign event types to EEG.event
for i = 1:length(event_types)
EEG.event(i).type = event_types{i};
End
Upon running the provided code with this data, everything works fine and as expected. However, when I executed the provided code with the following data:
EEG = struct();
% Define the event types as an array of numbers
event_types = [108, 109, 110, 111, 112, 113, 114, 111, 116, 117, 111];
% Use a for loop to assign event types to EEG.event
for i = 1:length(event_types)
EEG.event(i).type = event_types(i);
End
It results in the error: "Error using str2num: Input must be a character vector or string scalar”. To resolve the issue, please verify the data type of the "type" field within the EEG.event structure.
I hope this helps!

类别

Help CenterFile Exchange 中查找有关 EEG/MEG/ECoG 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by