motion_cond = [1, 2];
snd_cond = [1, 2];
subjects = 1:10;
X = zeros(length(motion_cond)*length(snd_cond)*length(subjects), 1);
factor1 = X;
factor2 = X;
repetitions = X;
m=1;
for i = 1:length(motion_cond)
    for j = 1:length(snd_cond)
        for k = 1:length(subjects)
            factor1(m)=i;
            factor2(m)=j;
            repetitions(m)=k;
            X(m) = mean(data(data(:, 5)==motion_cond(i) & ...
            data(:,6)==snd_cond(j) & data(:, 1)==repetitions(k), 7));
            m = m + 1;
        end
    end
end