Hello,
I would like to plot a 2D matrix where rows and columns are coordinates and the cell value is assigned a specific color. My data is a bit more complex, but to illustrate I made some simple code plotting a sine wave.
[X,Y] = meshgrid(linspace(-1/2*pi,1/2*pi));Z1 = cos(X).*cos(Y);Z2 = 2*cos(X).*cos(Y);% 2D figure
figure;subplot(1,2,1);surface(X,Y,Z1,'EdgeColor','flat','LineStyle','none','FaceColor','flat');subplot(1,2,2);surface(X,Y,Z2,'EdgeColor','flat','LineStyle','none','FaceColor','flat');% 3D figure
figure;subplot(1,2,1);surf(X,Y,Z1,'EdgeColor','flat','LineStyle','none','FaceColor','flat');subplot(1,2,2);surf(X,Y,Z2,'EdgeColor','flat','LineStyle','none','FaceColor','flat');
As you can see, one figure shows the sine waves as a 2D, one as a 3D figure. My problem is: I would like one given color to represent the same value in both subplots. As you can see, the amplitude in the second subplot is twice as high, but the colors used are the same!
My second problem is: I instead of continous colors, I would like to use categorical colors. For example, yellow for 0.2 < z <= 0.4 and green for 0.4 < z <= 0.6. The categories and the border between them should then be identical in both subplots. Please note that this means more categories will be required for subplot 2 as the range is larger.
It would be great if someone could help me with one or both of these problems!
Thanks,
Toby
Best Answer