Filtering out rows of data based on criteria from different columns in MATLAB -
i have data experiment in each row different trial. table has several columns information trial, , 1000 columns of data.
i need filter out trials (rows) based on various criteria in order calculate means valid trials only. example, have column accuracy data (0 = error, 1 = correct), , column response time data (need filter out responses < 200). assume need loop through each row create new true/false logical column based on criteria (e.g., valid trials accuracy == 1 & rt > 200).
then, need create means of valid trials grouped conditions defined strings in column (e.g., create 3 means based on valence column "negative", "neutral" , "positive"). know relatively simple do, new matlab. suggestions appreciated.
valence acc rts numnan data1 'negative' 1 540 0 278.5148611 'negative' 1 597 0 89.18152778 'negative' 1 381 0 173.5148611 'negative' 1 471 0 19.51486111 'negative' 1 535 0 2.514861111
you can operate boolean logic.
suppose data stored in matrix a
.
cond1 = a(:,2) == 1; % select 'accurate' data cond2 = a(:,3) < 200; % response time <200 cond3 = a(:,1) ~= 'negative'; % non-negative trials idx = cond1 & cond2 & cond3; % use 'and' logic find indices of satisfying records b = a(idx,:); % pick out selected records , save in new matrix
Comments
Post a Comment