Lect 1
Lect 1
Abstract : Learn the basic features of Matlab, and learn how to load and visualize signals and images.
Create a variable and an array % this is a comment a = 1; a = 2+1i; % real and complex numbers b = [1 2 3 4]; % row vector c = [1; 2; 3; 4]; % column vector d = 1:2:7; % here one has d=[1 3 5 7] A = eye(4); B = ones(4); C = rand(4); % identity, 1 and random matrices c = b'; % transpose
Modification of vectors and matrices A(2,2) = B(1,1) + b(1); % to access an entry in a vector or matrix b(1:3) = 0; % to access a set of indices in a matrix b(end-2:end) = 1: % to access the last entries b = b(end:-1:1); % reverse a vector b = sort(b); % sort values b = b .* (b>2); % set to zeros (threshold) the values below 2 b(3) = []; % supress the 3rd entry of a vector B = [b; b]; % create a matrix of size 2x4 c = B(:,2); % to access 2nd column
Advanced instructions a = cos(b); a = sqrt(b); % usual function help perform_wavelet_transform; % print the help a = abs(b); a = real(b); a = imag(b); a = angle(b); % norm, real part and imaginary part of a complex disp('Hello'); % display a text disp( sprintf('Valeur de x=%.2f', x) ); % print a values with 2 digits A(A==Inf) = 3; % replace Inf values by 3 A(:); % flatten a matrix into a column vector max(A(:)); % max of a matrix M = M .* (abs(M)>T); % threshold to 0 values below T.
Display
plot( 1:10, (1:10).^2 ); % display a 1D function title('Mon titre'); % title xlabel('variable x'); ylabel('variable y'); % axis subplot(2, 2, 1); % divide the screen in 2x2 and select 1st quadrant
Programmation for i=1:4 % disp(i); end i = 4; while i>0 % disp(i); i = i-1; end repeat the loop for i=1, i=2, i=3 et i=4 % make here something while syntax % do smth
Load and plot a signal : (function load_signal.m should be in the toolbox of each course) f = load_signal('Piece-Regular', n); % signal of size n plot(f);
Load and display an image (download function load_image.m should be in the toolboxes) I = load_image('lena'); imagesc(I); axis image; colormap gray(256);