%%% Gives individual SEM and p value for difference in mean of unpaired
%%% distributions
function [p, sem1, sem2] = bootstrap_p_sem_unpaired(x,y)
        
    n = length(x);
    m = length(y);

    t = ( mean(x) - mean(y) ) / sqrt( var(x)/n + var(y)/m );

    z = [x y];

    itr_num = 1000000;
    t2 = zeros(1, itr_num);
    m1 = zeros(1, itr_num);
    m2 = zeros(1, itr_num);        
    for itr = 1:itr_num
        x2 = datasample(z, n);
        y2 = datasample(z, m);

        m1(itr) = mean(x2);
        m2(itr) = mean(y2);

        t2(itr) = ( mean(x2) - mean(y2) ) / sqrt( var(x2)/n + var(y2)/m );

    end

    p = length(find(t2>=t)) / length(t2);
    sem1 = std(m1);
    sem2 = std(m2);


end