show2dData

show2dData - % find max max = numbers_sorted(w); min =...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
function colr = show2dData(M,maxColr) % Show values in matrix M as an intensity plot and return the color data. .. % as a cell array. % M is a matrix of numeric values; M is not empty. % maxColr is an rgb vector representing a color. % colr is a 2-d cell array such that colr{r,c} is an rgb vector that % represents the value in M(r,c), where r and c are valid row and column % indices of matrix M. The maximum value in M corresponds to the color % maxColr. The minimum value in M corresponds to the color white. Other % values in M have colors that are linearly interpolated between maxColr % and white [nr, nc] = size(M); % find the dimensions of M numbers = zeros(1,nr*nc); % initialize vector to hold all values p = 1; for k = 1:nr % make vector for j = 1:nc numbers(p) = M(k,j); p=p+1; end end numbers_sorted = sort(numbers); % arrange in ascending order close all figure axis equal off hold on w = length(numbers_sorted);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % find max max = numbers_sorted(w); min = numbers_sorted(1); range = max - min; white = [1 1 1]; colr = cell(nr, nc); % make a cell to hold all colors HA = 'HorizontalAlignment'; HV = 'VerticalAlignment'; for k = 1:nr for j = 1:nc f = ((M(k,j)-min)/range); colr{k,j} = (1-f)*white + f*maxColr; % find the colors x = [ (j-1) j j (j-1)]; y = [(nr-k) (nr-k) (nr-k+1) (nr-k+1)]; fill(x,y,colr{k,j}); numb = sprintf('%d',M(k,j)); % have variables hold text col = sprintf('[%.2f, %.2f, %.2f]', colr{k,j}(1), . .. colr{k,j}(2), colr{k,j}(3)); if nr<=4 && nc<=4 text(j-.5,(nr-k+.5), numb, . .. HA, 'center', HV, 'bottom') text(j-.5,(nr-k+.5), col, . .. HA, 'center', HV, 'top') elseif nr<=6 && nc<=6 text(j-.5,(nr-k+.5), numb, HA, 'center') else end end end % print title title(sprintf('Max Value has color [%.2f, %.2f, %.2f]',. .. maxColr(1), maxColr(2), maxColr(3))) hold off shg...
View Full Document

This note was uploaded on 03/28/2012 for the course CS 9339 at Cornell.

Page1 / 2

show2dData - % find max max = numbers_sorted(w); min =...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online