diff --git a/linearalgebra/code/coordinaterafo2.m b/linearalgebra/code/coordinaterafo2.m deleted file mode 100644 index 054ac6d..0000000 --- a/linearalgebra/code/coordinaterafo2.m +++ /dev/null @@ -1,52 +0,0 @@ -% some vectors: -x = [ -1:0.02:1 ]; -y = x*0.5 + 0.1*randn( size(x) ); -plot( x, y, '.b' ); -hold on -plot( x(10), y(10), '.r' ); - -% new coordinate system: -%e1 = [ 3/5 4/5 ]; -%e2 = [ -4/5 3/5 ]; -e1 = [ 3 4 ]; -e2 = [ -4 3 ]; -me1 = sqrt( e1*e1' ); -e1 = e1/me1; -me2 = sqrt( e2*e2' ); -e2 = e2/me2; -quiver( 0.0, 0.0 , e1(1), e1(2), 1.0, 'r' ) -quiver( 0.0, 0.0 , e2(1), e2(2), 1.0, 'g' ) -axis( 'equal' ) - -% project [x y] onto e1 and e2: - -% % the long way: -% nx = zeros( size( x ) ); % new x coordinate -% ny = zeros( size( y ) ); % new y coordinates -% for k=1:length(x) -% xvec = [ x(k) y(k) ]; -% nx(k) = xvec * e1'; -% ny(k) = xvec * e2'; -% end -% plot( nx, ny, '.g' ); - -% the short way: -%nx = [ x' y' ] * e1'; -%nx = [x; y]' * e1'; -% nx = e1 * [ x; y ]; -% ny = e2 * [ x; y ]; -% plot( nx, ny, '.g' ); - -% even shorter: -n = [e1; e2 ] * [ x; y ]; -plot( n(1,:), n(2,:), '.g' ); - - - - - - - - - -hold off diff --git a/linearalgebra/code/coordinatetrafo.m b/linearalgebra/code/coordinatetrafo.m index 7c8507c..a1fd836 100644 --- a/linearalgebra/code/coordinatetrafo.m +++ b/linearalgebra/code/coordinatetrafo.m @@ -35,3 +35,4 @@ xlabel( 'x' ); ylabel( 'y' ); hold off; +pause; diff --git a/linearalgebra/code/covareigen.m b/linearalgebra/code/covareigen.m index cd6025f..03431f4 100644 --- a/linearalgebra/code/covareigen.m +++ b/linearalgebra/code/covareigen.m @@ -38,11 +38,11 @@ function covareigen( x, y, pm, w, h ) colormap( 'gray' ); else % scatter plot: - scatter( x, y, 'b', 'filled', 'MarkerEdgeColor', 'white' ); + scatter( x, y ); %, 'b', 'filled', 'MarkerEdgeColor', 'white' ); end % plot eigenvectors: - quiver( ones( 1, 2 ).*mean( x ), ones( 1, 2 )*mean(y), v(1,:).*sqrt(diag(d))', v(2,:).*sqrt(diag(d))', 'r', 'LineWidth', 3, 'AutoScale', 'off', 'AutoScaleFactor', 1.0, 'MaxHeadSize', 0.7 ) + quiver( ones( 1, 2 ).*mean( x ), ones( 1, 2 )*mean(y), v(1,:).*sqrt(diag(d))', v(2,:).*sqrt(diag(d))', 'r', 'LineWidth', 3 ); %, 'AutoScale', 'off', 'AutoScaleFactor', 1.0, 'MaxHeadSize', 0.7 ) xlabel( 'x' ); ylabel( 'y' ); @@ -76,7 +76,7 @@ function covareigen( x, y, pm, w, h ) contourf( xp, yp, gauss ) end else - scatter( nc(:,1), nc(:,2), 'b', 'filled', 'MarkerEdgeColor', 'white' ); + scatter( nc(:,1), nc(:,2) ); %, 'b', 'filled', 'MarkerEdgeColor', 'white' ); end xlabel( 'x' ); ylabel( 'y' ); diff --git a/linearalgebra/code/covareigen3.m b/linearalgebra/code/covareigen3.m index 636d9cb..ec4bee4 100644 --- a/linearalgebra/code/covareigen3.m +++ b/linearalgebra/code/covareigen3.m @@ -15,29 +15,29 @@ function covareigen3( x, y, z ) % scatter plot: view( 3 ); - scatter3( x, y, z, 0.1, 'b', 'filled', 'MarkerEdgeColor', 'blue' ); +scatter3( x, y, z, 0.1, 'b', 'filled' ); %, 'MarkerEdgeColor', 'blue' ); xlabel( 'x' ); ylabel( 'y' ); zlabel( 'z' ); grid on; % plot eigenvectors: - quiver3( ones( 1, 3 ).*mean( x ), ones( 1, 3 )*mean(y), ones( 1, 3 )*mean(z), v(1,:).*sqrt(diag(d))', v(2,:).*sqrt(diag(d))', v(3,:).*sqrt(diag(d))', 'r', 'LineWidth', 3, 'AutoScale', 'off', 'AutoScaleFactor', 1.0, 'MaxHeadSize', 0.7 ) + quiver3( ones( 1, 3 ).*mean( x ), ones( 1, 3 )*mean(y), ones( 1, 3 )*mean(z), v(1,:).*sqrt(diag(d))', v(2,:).*sqrt(diag(d))', v(3,:).*sqrt(diag(d))', 'r' ); %, 'LineWidth', 3, 'AutoScale', 'off', 'AutoScaleFactor', 1.0, 'MaxHeadSize', 0.7 ) %axis( 'equal' ); hold off; % 2D scatter plots: subplot( 2, 6, 4 ); - scatter( x, y, 'b', 'filled', 'MarkerEdgeColor', 'white' ); + scatter( x, y, 'b', 'filled' ); %, 'MarkerEdgeColor', 'white' ); xlabel( 'x' ) ylabel( 'y' ) subplot( 2, 6, 5 ); - scatter( x, z, 'b', 'filled', 'MarkerEdgeColor', 'white' ); + scatter( x, z, 'b', 'filled' ); %, 'MarkerEdgeColor', 'white' ); xlabel( 'x' ) ylabel( 'z' ) subplot( 2, 6, 6 ); - scatter( y, z, 'b', 'filled', 'MarkerEdgeColor', 'white' ); + scatter( y, z, 'b', 'filled' ); %, 'MarkerEdgeColor', 'white' ); xlabel( 'y' ) ylabel( 'z' ) @@ -51,7 +51,7 @@ function covareigen3( x, y, z ) y = y - mean( y ); % project onto eigenvectors: nx = [ x y z ] * v(:,inx); - scatter( nx(:,1), nx(:,2), 'b', 'filled', 'MarkerEdgeColor', 'white' ); + scatter( nx(:,1), nx(:,2), 'b', 'filled' ); %, 'MarkerEdgeColor', 'white' ); xlabel( 'ex' ) ylabel( 'ey' ) axis( 'equal' ); diff --git a/linearalgebra/code/covareigen3examples.m b/linearalgebra/code/covareigen3examples.m index f27c76c..faefbde 100644 --- a/linearalgebra/code/covareigen3examples.m +++ b/linearalgebra/code/covareigen3examples.m @@ -1,6 +1,3 @@ -scrsz = get( 0, 'ScreenSize' ); -set( 0, 'DefaultFigurePosition', [ scrsz(3)/2 scrsz(4)/2 scrsz(3)/2 scrsz(4)/2 ] ); - n = 10000; % three distributions: @@ -17,3 +14,4 @@ for k = 1:4 end f = figure( 1 ); covareigen3( x, y, z ); +pause; diff --git a/linearalgebra/code/covareigenexamples.m b/linearalgebra/code/covareigenexamples.m index 2f7a480..5b7262d 100644 --- a/linearalgebra/code/covareigenexamples.m +++ b/linearalgebra/code/covareigenexamples.m @@ -1,6 +1,3 @@ -scrsz = get( 0, 'ScreenSize' ); -set( 0, 'DefaultFigurePosition', [ scrsz(3)/2 scrsz(4)/2 scrsz(3)/2 scrsz(4)/2 ] ); - % correlation coefficients: n = 10000; x = randn( n, 1 ); @@ -10,9 +7,9 @@ for r = 0.01:0.19:1 clf( f ); y = r*x + sqrt(1-r^2)*randn( n, 1 ); covareigen( x, y, 0, 5.0, 3.0 ); - key = waitforbuttonpress; + %key = waitforbuttonpress; + pause( 1.0 ); end -return % two distributions: n = 10000; @@ -21,14 +18,12 @@ y1 = randn( n/2, 1 ); x2 = randn( n/2, 1 ); y2 = randn( n/2, 1 ); f = figure( 1 ); -pause( 'on' ); for d = 0:1:5 fprintf( 'Distance = %g\n', d ); clf( f ); d2 = d / sqrt( 2.0 ); x = [ x1; x2 ]; y = [ y1+d2; y2-d2 ]; - scrsz = get(0,'ScreenSize'); covareigen( x, y, 0, 10.0, 7.0 ); %key = waitforbuttonpress; pause( 1.0 ); diff --git a/linearalgebra/code/matrixbox.m b/linearalgebra/code/matrixbox.m index 6cc0aa1..4686dba 100644 --- a/linearalgebra/code/matrixbox.m +++ b/linearalgebra/code/matrixbox.m @@ -41,5 +41,5 @@ function matrixbox( m, s ) text( 0.8, 0.1, sprintf( '%.3g', m(2,1) ), 'Units', 'normalized' ) text( 0.9, 0.1, sprintf( '%.3g', m(2,2) ), 'Units', 'normalized' ) title( s ); - waitforbuttonpress; + pause(1.0); end diff --git a/linearalgebra/code/pca2d.m b/linearalgebra/code/pca2d.m index 6879f8a..84e217f 100644 --- a/linearalgebra/code/pca2d.m +++ b/linearalgebra/code/pca2d.m @@ -39,7 +39,7 @@ function pca2d( x, y, pm, w, h ) colormap( 'gray' ); else % scatter plot: - scatter( x, y, 'b', 'filled', 'MarkerEdgeColor', 'white' ); + scatter( x, y, 'b', 'filled' );%, 'MarkerEdgeColor', 'white' ); end % plot eigenvectors: @@ -80,7 +80,7 @@ function pca2d( x, y, pm, w, h ) end else % scatter plot: - scatter( nc(:,1), nc(:,2), 'b', 'filled', 'MarkerEdgeColor', 'white' ); + scatter( nc(:,1), nc(:,2), 'b', 'filled' ); %, 'MarkerEdgeColor', 'white' ); end xlabel( 'n_x' ); ylabel( 'n_y' ); diff --git a/linearalgebra/code/pca2dexamples.m b/linearalgebra/code/pca2dexamples.m index 252ceda..15552f3 100644 --- a/linearalgebra/code/pca2dexamples.m +++ b/linearalgebra/code/pca2dexamples.m @@ -1,6 +1,3 @@ -scrsz = get( 0, 'ScreenSize' ); -set( 0, 'DefaultFigurePosition', [ scrsz(3)/2 scrsz(4)/2 scrsz(3)/2 scrsz(4)/2 ] ); - % correlation coefficients: n = 10000; x = randn( n, 1 ); @@ -27,7 +24,6 @@ for d = 0:1:5 d2 = d / sqrt( 2.0 ); x = [ x1; x2 ]; y = [ y1+d2; y2-d2 ]; - scrsz = get(0,'ScreenSize'); pca2d( x, y, 0, 10.0, 7.0 ); waitforbuttonpress; end diff --git a/linearalgebra/code/pca3d.m b/linearalgebra/code/pca3d.m index 6f2a6bd..e967faf 100644 --- a/linearalgebra/code/pca3d.m +++ b/linearalgebra/code/pca3d.m @@ -15,29 +15,29 @@ function pca3d( x, y, z ) % scatter plot: view( 3 ); - scatter3( x, y, z, 0.1, 'b', 'filled', 'MarkerEdgeColor', 'blue' ); + scatter3( x, y, z ); % , 0.1, 'b', 'filled', 'MarkerEdgeColor', 'blue' ); xlabel( 'x' ); ylabel( 'y' ); zlabel( 'z' ); grid on; % plot eigenvectors: - quiver3( ones( 1, 3 ).*mean( x ), ones( 1, 3 )*mean(y), ones( 1, 3 )*mean(z), v(1,:).*sqrt(diag(d))', v(2,:).*sqrt(diag(d))', v(3,:).*sqrt(diag(d))', 'r', 'LineWidth', 3, 'AutoScale', 'off', 'AutoScaleFactor', 1.0, 'MaxHeadSize', 0.7 ) + quiver3( ones( 1, 3 ).*mean( x ), ones( 1, 3 )*mean(y), ones( 1, 3 )*mean(z), v(1,:).*sqrt(diag(d))', v(2,:).*sqrt(diag(d))', v(3,:).*sqrt(diag(d))', 'r' ); %, 'LineWidth', 3, 'AutoScale', 'off', 'AutoScaleFactor', 1.0, 'MaxHeadSize', 0.7 ) %axis( 'equal' ); hold off; % 2D scatter plots: subplot( 2, 6, 4 ); - scatter( x, y, 'b', 'filled', 'MarkerEdgeColor', 'white' ); + scatter( x, y, 'b', 'filled' ); %, 'MarkerEdgeColor', 'white' ); xlabel( 'x' ) ylabel( 'y' ) subplot( 2, 6, 5 ); - scatter( x, z, 'b', 'filled', 'MarkerEdgeColor', 'white' ); + scatter( x, z, 'b', 'filled' ); %, 'MarkerEdgeColor', 'white' ); xlabel( 'x' ) ylabel( 'z' ) subplot( 2, 6, 6 ); - scatter( y, z, 'b', 'filled', 'MarkerEdgeColor', 'white' ); + scatter( y, z, 'b', 'filled' ); %, 'MarkerEdgeColor', 'white' ); xlabel( 'y' ) ylabel( 'z' ) @@ -51,10 +51,11 @@ function pca3d( x, y, z ) y = y - mean( y ); % project onto eigenvectors: nx = [ x y z ] * v(:,inx); - scatter( nx(:,1), nx(:,2), 'b', 'filled', 'MarkerEdgeColor', 'white' ); + scatter( nx(:,1), nx(:,2), 'b', 'filled' ); %, 'MarkerEdgeColor', 'white' ); xlabel( 'ex' ) ylabel( 'ey' ) axis( 'equal' ); hold off; end + diff --git a/linearalgebra/code/pca3dexamples.m b/linearalgebra/code/pca3dexamples.m index d2d790f..7abc511 100644 --- a/linearalgebra/code/pca3dexamples.m +++ b/linearalgebra/code/pca3dexamples.m @@ -17,3 +17,4 @@ for k = 1:4 end f = figure( 1 ); pca3d( x, y, z ); +pause diff --git a/linearalgebra/code/simplematrixbox.m b/linearalgebra/code/simplematrixbox.m index bb94254..b96f5cd 100644 --- a/linearalgebra/code/simplematrixbox.m +++ b/linearalgebra/code/simplematrixbox.m @@ -17,5 +17,5 @@ function simplematrixbox( a, s ) xlim( [-2 2 ] ) ylim( [-2 2] ) title( s ); - waitforbuttonpress; + pause(1.0); end diff --git a/linearalgebra/code/spikesortingwave.m b/linearalgebra/code/spikesortingwave.m index da7c251..d833ad2 100644 --- a/linearalgebra/code/spikesortingwave.m +++ b/linearalgebra/code/spikesortingwave.m @@ -5,21 +5,22 @@ load( 'extdata' ); dt = time( 2) - time(1); tinx = round(spiketimes/dt)+1; -% plot voltage trace with dettected spikes: +% plot voltage trace with detected spikes: figure( 1 ); clf; plot( time, voltage, '-b' ) hold on scatter( time(tinx), voltage(tinx), 'r', 'filled' ); -xlabel( 'time [ms]' ); +xlabel( 'time [s]' ); ylabel( 'voltage' ); +xlim([0.1, 0.4]) hold off % spike waveform snippets: w = ceil( 0.005/dt ); -vs = []; +vs = zeros(length(tinx), 2*w); for k=1:length(tinx) - vs = [ vs; voltage(tinx(k)-w:tinx(k)+w-1) ]; + vs(k,:) = voltage(tinx(k)-w:tinx(k)+w-1); end ts = time(1:size(vs,2)); ts = ts - ts(floor(length(ts)/2)); @@ -78,9 +79,9 @@ kx = ones( size( nx ) ); kx(nx