function bookfig2mesh(a) % Simple script to generate Figure 2, chapter 14 WITHOUT SPM! Just Matlab % Book: Human Brain Function. Academic Press, 2nd edition, 2003 % Authors: Frackowiak, Friston, Frith, Dolan, Price, Zeki, Ashburner, and Penny. % Script source: http://www.poirrier.be/~jean-etienne/presentations/rft/ % !!!!! YOU SHOULD HAVE RUN SCRIPT bookfig1.m BEFORE THIS ONE % !!!!!!!!!! IN ORDER TO HAVE THE CORRECT AND SAME 'a' MATRIX ! % How to run it? "bookfig2mesh(a);" % Argument 'a' is the square ramdom map from script bookfig1! % The DIFFERENCE with bookfig2.m is here: graph = MESH (instead of imagesc) % Clear screen clf; close; % Compute replacement of random values by the mean within each square dim = 10; % square dimension --> can be modified for any other dimension nsquare = 100 / dim; % number of squares in one dimension of image sum = 0; % sum of values for each square n = 0; % number of values collected in each square for i = 1:nsquare for j = 1:nsquare % traverse each square to collect random data for k = ((i - 1) * 10 + 1):((i - 1) * 10 + 10) for l = ((j - 1) * 10 + 1):((j - 1) * 10 + 10) % get data sum = sum + a(k, l); n = n + 1; end end mean = sum / n; % traverse each square to put means data for k = ((i - 1) * 10 + 1):((i - 1) * 10 + 10) for l = ((j - 1) * 10 + 1):((j - 1) * 10 + 10) % put the mean a(k, l) = mean; end end % reset values sum = 0; n = 0; end end h = mesh(a); % Beautify image set(gca,'YDir','normal'); colormap(gray); ylabel('Position du pixel en Y'); xlabel('Position du pixel en X');