
% Assignment 5 a b.
% Takes as parameter:
% a scalar probability 'p' of how often data is generated from source 1,
% and how often from source 2.
% 
% a 1x2 vector containing averages of normal distributions, 'avg'.
% a 1x2 vector containing variances of normal distributions, 'var'.
% amount of samples to generate, 'n'.
function [x, y] = JKO_01_05(p, avg, var, n)

% go through values 1->n.
for i=1:n;
    
    % generate a value from a uniform distribution between 0 and 1.
    a = rand();
    
    % if less than probability p, then use generator 1.
    if (a < p)
        y(i) = 0;
        x(i) = avg(1) + var(1).*randn();
    else
        % otherwise use generator 2.
        y(i) = 1;
        x(i) = avg(2) + var(2).*randn();
    end
end

% visualize answer.
scatter(x, y);
