% trigimage.m displays an intensity plot of a trig field as an image, as a way of understanding the differences between matrices and images. Then it changes the colormaps. gridsize = [80 80]; % number of grid points in x, y gridrange= [0 10 0 10]; % default [xmin xmax ymin ymax] [x,y] = easygrid(gridrange, gridsize); % matrices of x and y values Z = zeros(gridsize); m = 100; % number of Fourier modes A = randn(1,m)*sqrt(2/m); % amplitudes of Fourier modes phi = 2 * pi * rand(m,1); % random phase norm = sqrt(-2*log(rand(m,1))); % magnitudes of wave numbers norm = 1 + 2*round(rand(m,1)) + 0.1*rand(m,1); % magnitudes of wave numbers theta = 2 * pi * rand(m,1); % arguments of wave numbers K = [norm.*cos(theta) norm.*sin(theta)]; % isotropic wave numbers for i=1:gridsize(1), % step through grid points for j=1:gridsize(2), Z(i,j) = A * cos(K*[x(i,j); y(i,j)] + phi); % compute field value at x,y end end clf colormap('default') subplot(2,2,1) imagesc(Z); % scale Z values into [0,1] title('Matrix Z plotted as an image, automatically scaled') colorbar subplot(2,2,2) W = Z-min(min(Z)); W = 64*W/max(max((W))); image(W); title('Matrix Z plotted as an image, manually scaled') subplot(2,2,3) pcolor(Z); shading flat title('Matrix Z plotted with pcolor'); jet fprintf('Now we will look at different colormaps.\n'); fprintf('The matrix Z has real entries, which get scaled from 1 to 64.\n'); fprintf('Whatever the value of Z, Matlab looks at the corresponding row\n'); fprintf('of the 64 by 3 matrix colormap to see with what intensity it\n'); fprintf('should give to blue, green, and red.\n'); fprintf('In the default colormap jet, low Z values go with blue, medium\n'); fprintf('with green, and high with red.\n'); pause fprintf('In the gray colormap you see here, all colors have equal\n'); fprintf('intensities, and the result is varying intensities of white.\n'); colormap(gray) pause colormap('default') pause colormap(hot) pause colormap(copper) pause colormap(cool) pause colormap(winter) pause colormap(hsv)