%% Programming Languages Matlab 3101 - Class 3 % 3/26/08, Instructor: Blake Shaw %% Short class because of Quiz %% Review % cells, strings, avoiding loops, creating indexes s = 'hello' x = double(s) char(x + 1) strfind('hello my name is blake', 'name') A = cell(5, 1); A{1} = 'this is a string'; A{2} = rand(5, 5); figure(1); cellplot(A); %% a = round(10*rand(10, 1)); b = round(10*rand(10, 10)); %% a circshift(a, 2) b %% sqrt(sum((b - repmat(a, 1, 10)).^2)) %% A = rand(10, 10); A A(A > 0.7) = 0; A [i, j] = find(A > 0.3) %% 3:2:54 linspace(-10, 10, 56) logspace(-1, 1, 10) %% Figures % figure, clf, gcf, hold, savesas figure(1); plot(sin(-2*pi:0.1:2*pi)); figure(2); plot(cos(-2*pi:0.1:2*pi)); gcf %% figure(1); clf; hold on; plot(-2*pi:0.1:2*pi, sin(-2*pi:0.1:2*pi), 'r+'); plot(-2*pi:0.1:2*pi, cos(-2*pi:0.1:2*pi), '*'); title('Sin and Cosine'); ylabel('Magnitude'); xlabel('Phase'); hold off; saveas(gcf, 'myFirstFigure.png'); %% Simple animation % drawnow figure(1); clf; for i=0:0.1:30 x = -2*pi:0.1:2*pi; x = x+i; plot(x, sin(x), 'r+'); drawnow; %saveas(gcf, sprintf('myFirstFigure%d.png', i)); end %% User input % ginput, input x = input('What is the temperature today? '); disp(sprintf('The temp is %d', x)); %% s = input('How are you doing today? ', 's'); s %% Images % imagesc, importdata, imread, imwrite figure(1); clf; X = rand(10, 10); imagesc(X); axis image; colormap('jet'); %% X = importdata('pine.jpg'); figure(2); clf; imagesc(X); axis image; Y = mean(X, 3); figure(3); clf; imagesc(Y); axis image; colormap('hot'); %% X = imread('pine.jpg'); %% Y = uint8(255); figure(3); saveas(gcf, 'pineHot.jpg'); imwrite(Y, 'pineHot2.png', 'png'); %% figure(1); clf; X = rand(10, 10); imagesc(X); axis image; colormap('jet'); for i=1:10 [x, y] = ginput(1) x = round(x); y = round(y); X(y, x) = 0; imagesc(X); axis image; colormap('jet'); end %% Colormaps and different kinds of images % colormap %% Convolution % conv2, xcorr2