% % TEST 1 - SECTION 1 % Sample Solutions % clear all; % QUESTION #1: % Generate a signal [1 2 3 1 2 3 ... ] of length 3000. signal = reshape([ones(1,1000); 2*ones(1,1000); 3*ones(1,1000)], 1, 3000); % QUESTION #2: % Cap a function and plot it x = 0 : 0.1 : 16*pi; y = sin(sqrt(x)); y(find(y>0.4))=0.4; y(find(y<-0.4))=-0.4; plot(x,y); title('Question 2: Capping a function to 0.4(max) and -0.4(min)'); xlabel('X'); ylabel('y = sin(sqrt(x)) [capped]'); axis([0 max(x) -1 1]); pause; % QUESTION #3: For tyhe above plot, do the following... % a) Make the background blue set(gcf, 'Color', 'Blue'); % b) Print your name (and nothing else) in the figure title set(gcf, 'Name', 'Matt Lab'); set(gcf, 'NumberTitle', 'off'); % c) Make the axes background white set(gca, 'Color', 'White'); % d) Make the axis color red set(gca, 'Xcolor', 'Red', 'YColor', 'Red'); pause; % QUESTION #4: z = sin(sqrt(x^2 + y^2)) % a) Plot z over the range -pi to pi in increments of 0.2 x = -pi : 0.2 : pi; y = x; [ X, Y ] = meshgrid(x, y); z = sin(sqrt(X.^2 + Y.^2)); mesh(z); pause; % b) Colormap such that: % Lowest value is blue (i.e. [ 0 0 1 ]) % Middle values are hot % Highest value is red (i.e. [ 1 0 0 ]) colormap([ [0 0 1]; hot; [1 0 0] ])