From: Rhys on 3 Jun 2010 07:02 Hi, I have put together this sample code, which half does what I need. I am trying to delete any trialID rows which do not have two trials, so 3, 5, 7, 8, 15 and 21 in this example. It works until there is a break in the sequence... Any suggestions? I may have over complicated it! thanks Rhys Sample code below _____________________________________________ trialID = [ 1 1 2 2 3 3 3 4 4 5 6 6 7 7 7 7 8 9 9 13 13 15 20 20 21 22 22]'; data = magic(length(trialID)); dataMatrix = [trialID data]; % data matrix, trial ID first column % get rid of all trials that have more % or fewer than have 2 rows only [unSubs,trash,subs] = unique(dataMatrix(:,1)); [n, bin] =histc(subs, unSubs); NotTwoTrials = find(n~=2); deletetrialID = unSubs(NotTwoTrials); deleteme = []; for i = 1:length(deletetrialID) a = find(dataMatrix(:,1)== deletetrialID(i)); deleteme = [deleteme; a]; end dataMatrix(deleteme,:) = []; % works to a point, but should keep 9 % 13 20 and 22 also...
From: Rhys on 3 Jun 2010 07:26 Posted too early, although had spent this morning on it... found a post on a different website. This code works for me now. thanks trialID = [ 1 1 2 2 3 3 3 4 4 5 6 6 7 7 7 7 8 9 9 13 13 15 20 20 21 22 22]'; data = magic(length(trialID)); dataMatrix = [trialID data]; % data matrix, trial ID first column Aset=unique(dataMatrix(:,1)) count=hist(dataMatrix(:,1),Aset)'; answermat = [Aset count] NotTwoTrials = find(count~=2); IncorrectTrialID = Aset(NotTwoTrials) deletetrialID = unSubs(NotTwoTrials); deleteme = []; for i = 1:length(deletetrialID) a = find(dataMatrix(:,1)== deletetrialID(i)); deleteme = [deleteme; a]; end dataMatrix(deleteme,:) = [];
From: Rhys on 3 Jun 2010 07:35 clc trialID = [ 1 1 2 2 3 3 3 4 4 5 6 6 7 7 7 7 8 9 9 13 13 15 20 20 21 22 22]'; data = magic(length(trialID)); dataMatrix = [trialID data]; Aset=unique(dataMatrix(:,1)); % unique trial ID's count=hist(dataMatrix(:,1),Aset)'; % how many of each trial NotTwoTrials = find(count~=2); deleteTrialID = Aset(NotTwoTrials); deleteme = []; for i = 1:length(deletetrialID) a = find(dataMatrix(:,1)== deletetrialID(i)); deleteme = [deleteme; a]; end dataMatrix(deleteme,:) = []
|
Pages: 1 Prev: Proper placement of downloaded exchange file Next: Stack histograms in a 3d plot |