>> z = zeros(20,20); >> o = ones(5,5); >> size(o) ans = 5 5 >> size(z) ans = 20 20 >> whos Name Size Bytes Class ans 1x2 16 double array o 5x5 200 double array z 20x20 3200 double array Grand total is 427 elements using 3416 bytes >> z(5:9,5:9)=o; >> x=[1:5;2:6] x = 1 2 3 4 5 2 3 4 5 6 >> sum(x) ans = 3 5 7 9 11 >> x(:) ans = 1 2 2 3 3 4 4 5 5 6 >> sum(x(:)) ans = 35 >> x(x>3)=0 x = 1 2 3 0 0 2 3 0 0 0 >> x([1,2,3,4]) ans = 1 2 2 3 >> x = [1:100]; >> tic >> for i = 1:100 if(x(i)>30) x(i)=0; end end >> toc elapsed_time = 14.1008 >> tic >> x(x>30)=1; >> toc elapsed_time = 4.9092 >> x = [1:5;2:6] x = 1 2 3 4 5 2 3 4 5 6 >> max(x) ans = 2 3 4 5 6 >> max(x(:)) ans = 6 >> I = find(x>3) I = 6 7 8 9 10 >> [I,J] = find(x>3) I = 2 1 2 1 2 J = 3 4 4 5 5 ___________________________________________________________ **** priklady **** >> b = linspace(1,10,10) b = 1 2 3 4 5 6 7 8 9 10 >> a=b(1:2:end) a = 1 3 5 7 9 >> X = [0 0 1 1 1 0 1 0; 1 0 0 1 0 0 1 1; 0 1 1 1 1 0 0 1; 1 1 1 0 0 0 1 0] X = 0 0 1 1 1 0 1 0 1 0 0 1 0 0 1 1 0 1 1 1 1 0 0 1 1 1 1 0 0 0 1 0 >> sum(X') ans = 4 4 5 4 >> max(sum(X')) ans = 5 x = Columns 1 through 7 0.8180 0.6602 0.3420 0.2897 0.3412 0.5341 0.7271 Columns 8 through 10 0.3093 0.8385 0.5681 >> plot(x) >> grid on >> imshow( X/max(X(:)) ); >> axis on >> XX = zeros(4*size(X)); >> XX(1:4:end,1:4:end) = X; >> imshow( XX/max(XX(:)) ); _______________________________________________________ **** druha cast **** >> image >> im = get(get(gca, 'children'), 'cdata' ); >> max(im(:)) ans = 31.2923 >> min(im(:)) ans = 3.6123 >> im = im/max(im(:))*255; >> max(im(:)) ans = 255 >> min(im(:)) ans = 29.4367 >> imshow( im/max(im(:)) ) >> imwrite(im, [0:255]'*[1 1 1], 'image.bmp', 'bmp' ); >> Im = imread( 'image.bmp' ); >> imshow(Im) >> im = Im(10:40, 10:40); >> imshow(im) >> imshow(Im) >> mesh(double(Im)) >> [x, y] = gradient(double(Im)); >> mesh( sqrt(x.^2+y.^2) ) >> figure >> imagesc( sqrt(x.^2+y.^2) ) >> close all _______________________________________________________________ **** echo treti cast **** >> x = [1 2 3]' x = 1 2 3 >> M = [1 2 3; 4 5 6; 7 8 9] M = 1 2 3 4 5 6 7 8 9 >> M*x ans = 14 32 50 >> x'*M ans = 30 36 42 >> x'*x ans = 14 >> x*x' ans = 1 2 3 2 4 6 3 6 9 >> cross(x,y) ans = -4 8 -4 >> dot(x,y) ans = 38 >> y'*x ans = 38 >> A = eye(3); >> A A = 1 0 0 0 1 0 0 0 1 >> rank(A) ans = 3 >> A(3,3) = 0; >> a a = 1 3 5 7 9 >> A A = 1 0 0 0 1 0 0 0 0 >> rank(A) ans = 2 >> A(3,3) = eps; >> A A = 1.0000 0 0 0 1.0000 0 0 0 0.0000 >> rank(A) ans = 2 >> A(3,3) = eps*10 A = 1.0000 0 0 0 1.0000 0 0 0 0.0000 >> rank(A) ans = 3 >> A = rand(3,3); >> [v, e] = eig( A * A' ); >> v v = 0.5432 -0.6748 0.4996 -0.7027 -0.0397 0.7104 0.4596 0.7370 0.4957 >> e e = 0.0032 0 0 0 0.0683 0 0 0 3.7450 >> v'*v ans = 1.0000 0.0000 0.0000 0.0000 1.0000 -0.0000 0.0000 -0.0000 1.0000 >> x = [1 2]' x = 1 2 >> A = [1 2; 0 1]; >> b = [3 4]'; >> y = A * x + b y = 8 6 >> y = [A,b]*[x;1] y = 8 6 >> >> >> >> diary off