12.07.2015 Views

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

R = 1; N = 200;[x,y] = meshgrid(linspace(-2,2,N));r = sqrt((x + 0.4).^2 + (y + 0.4).^2);ind = find(r>R);r(ind) = 0;g = sqrt((x - 0.4).^2 + (y + 0.4).^2);ind = find(g>R);g(ind) = 0;b = sqrt(x.^2 + (y - 0.4).^2);ind = find(b>R);b(ind) = 0;rgb = cat(3,r,g,b);imagesc(rgb)axis equal <strong>of</strong>fYou may find that the image on the screen has been dithered because wenow have a very large number <strong>of</strong> colours. You might like to investigateother combinations <strong>of</strong> red, green, <strong>and</strong> blue matrices, for example:r = peaks;g = r’;b = fftshift(r);Mixing linear ramps <strong>of</strong> colour in different directions is interesting. Beadventurous!Exercise 14 (Page 115)Since we know the dimensions <strong>of</strong> the borders in pixels, we set the figure’sunits property to pixels. It is then just a matter <strong>of</strong> taking into acountthe correct number <strong>of</strong> borders when defining the figures’ positions which,remember, don’t include the borders. The following code does the job.We start by getting the size <strong>of</strong> the screen (the root object, whose h<strong>and</strong>leis alway zero) in pixels.set(0,’Units’,’pixels’)screensize = get(0,’ScreenSize’);edgethickness = 5;topthickness = 10;scr_width = screensize(3);scr_height = screensize(4);figwidth = scr_width/2 - 2*edgethickness;figheight = scr_height/2 - ...2*(edgethickness + topthickness);pos1 = [edgethickness,...edgethickness,...figwidth,...figheight];c○ 2000 by CRC Press LLC

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!