How do I make a pcolor plot use the first row and column of the data for the X and Y axes?

I need to do an interactive image plot of data that are in matrix form. The first row and column are the X and Y values, the rest of the matrix represents the corresponding Z values. A pcolor plot plots all the data in the matrix. How do I make it use the first row and column for the X and Y axes?

 Accepted Answer

If I understand you correctly, you need to extract the first row/column and use meshgrid to build the grid for surf (better than pcolor in my opinion).
x = [nan, 1 2 5 10;
cumprod(1:4).',magic(4)]
[xx,yy] = meshgrid(x(1,2:end),x(2:end,1));
surf(xx,yy,x(2:end,2:end));
view(2)
x looks like this
nan x_index
yindex data

More Answers (1)

This is false: "A pcolor plot plots all the data in the matrix." Just try it
myMatrix = magic(4); % Make 4x4 array
pcolor(myMatrix); % Displays 3x3 image.
If I were you I'd use imshow() instead, or image() or imagesc().

Categories

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!