%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%% EE 156a %%%% S. Savarese - M. Welling %%%%%%% March 2000 %%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%% routine to plot the estimated 2D gaussian given N_points %%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear; clf; N_points_1 = input('Number of points you may want to select for the cluster (max 1000)= '); xs_1=zeros(1,N_points_1); ys_1=zeros(1,N_points_1); figure(1); axis([-100 100 -100 100]); hold on; %%%%%%%% acquire points %%%%%%%%%%%%%%%%%%% for i=1:N_points_1, fprintf(1,'%d - Select a point with the mouse: ',i); [x,y] = ginput2(1); fprintf(1,'(%3.3f,%3.3f)\n',x,y); plot(x,y,'r+'); xs_1(i)=x; ys_1(i)=y; end; xs_1; ys_1; s_1=[xs_1; ys_1]; mu_x_1 = sum(xs_1)/N_points_1 mu_y_1 = sum(ys_1)/N_points_1 %%%%%% mean vector %%%%%%%%%%%% mu_1= sum(s_1,2)/N_points_1 mat_1=ones(2,2,N_points_1); for i=1:N_points_1, mat_1(:,:,i)= (s_1(:,i)-mu_1)*(s_1(:,i)-mu_1)'; end; %mat_1(:,:,i)= (s_1(:,i)-mu_1)*(s_1(:,i)-mu_1)' %%%%%%%%% covariance matrix cov_1=sum(mat_1,3)/N_points_1 plotGauss(mu_1(1),mu_1(2),cov_1(1,1),cov_1(2,2),cov_1(1,2)) hold off;