Compare content of a cell that has text
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ramiro Rea
am 10 Jul. 2017
Kommentiert: Ramiro Rea
am 10 Jul. 2017
Hi everyone,
I am trying to extract some time values from a dataset. If a certain condition is satisfied, I want to obtain both the start time and the RT of each row, if not, I want to get a 0. I transformed the initial array into a table, and started to do comparisons there. In the code I am attaching (I hope is sufficiently documented), I compare the response (column5) with the location of a particular condition (e.g. gmax in column 2). If it matches, it returns the values from columns 6,7 (starttime and rt). I want to do this with column 1 (type) which contains three possible values ('rand','trad_zero','trad_neg'). If it matches 'rand' I want to get the start_time and rt from those rows(column 6&7), and save them as random_onsets & random_durations, respectively. Do you have any idea how can I do this? I am converting the array to a table, because is the only way I know how to make the other comparisons between columns (I am pretty new to matlab or any programming language). If you have a suggestion from the scratch, I would appreciate it too. Here is the code, I attached also a sample of the original data:
%%Load the behavioral data and tables for comparison
load ('Gamble_ET_1_S3_block1.mat', 'stim_choice')
%%Create a table with the values we wish to extract and name the variables accordingly
T = table({stim_choice.type}.', [stim_choice.gmax].', [stim_choice.pmax].', [stim_choice.lmin].', [stim_choice.resp_num].', [stim_choice.start_time].', [stim_choice.rt].', [stim_choice.end_time].', 'VariableNames', {'type', 'gmax', 'pmax', 'lmin', 'resp_num', 'start_time', 'rt', 'end_time'});
%%Compare location of variables vs response(column5) to obtain onsets (column6) and durations (column7)
A = (T{:,2} == T{:,[5 5]}).*T{:,6:7}; %gmax
B= (T{:,3} == T{:,[5 5]}).*T{:,6:7}; %pmax
C = (T{:,4} == T{:,[5 5]}).*T{:,6:7}; %lmin
%%Obtain onsets and durations of each condition
%Simple scenarios
decision_onsets = (T{:,6});
decision_durations = (T{:,7});
postdecision_onsets = (T{:,8}); % = End time
postdecision_durations = 12-(T{:,7}); % = Trial duration (12s) - rt
%Complex scenarios
%---------Separate onsets and durations & remove 0's--------
gmax_onsets = nonzeros (A(:,1));
gmax_durations = nonzeros (A(:,2));
pmax_onsets = nonzeros (B(:,1));
pmax_durations = nonzeros (B(:,2));
lmin_onsets = nonzeros (C(:,1));
lmin_durations = nonzeros (C(:,2));
Many thanks, Ramiro
2 Kommentare
KL
am 10 Jul. 2017
Your conditions are quite not clear. It would be easier if you tell us what do you expect in the resultant array/table.
Akzeptierte Antwort
KL
am 10 Jul. 2017
if you want to extract start_time and rt based on some conditions, you could create a boolean array.
gC = T.resp_num==T.gmax;
pC = T.resp_num==T.pmax;
tC = strcmp('rand',T.type);
pCT = [T.start_time(pC) T.rt(pC)]
gCT = [T.start_time(gC) T.rt(gC)]
tCT = [T.start_time(tC) T.rt(tC)]
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Identification finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!