how to setup a color matrix in surf(x,y,z,C) that has two components, one fixed, one related to data?

조회 수: 3 (최근 30일)
I am solving a wave like equation using the perfectly matched layer method, where an absorbing layer surrounds the domain of interest. I am able to compute the solution and want to plot it. So far what I have been doing is assigning the absorbing layer a fixed color, and the interior of the domain a checkerboard pattern using the code below and surf(X,Y,Z,C). However, I am wondering if it is possible to keep the color of the exterior boundary fixed, but have the interior of the domain have a color assigned related to the Z data.
C=zeros(N+2*Nl);
for n=1:N+2*Nl
for p=1:N+2*Nl
if n<=Nl || n>=(N+Nl) ||p<=Nl || p>=(N+Nl)
C(n,p)=1;
else
if mod(floor(n/10)+floor(p/10),2)==0
C(n,p)=4/3;
else
C(n,p)=5/3;
end
end
end
end
So far the plot looks like this one, but I would like to have instead of the checkerboard pattern the interior to have a colormap related to the z-data, and it would look as if you just used surf(X,Y,Z), but keeping the one color exterior layer.

채택된 답변

Patrick Kalita
Patrick Kalita 2012년 8월 28일
This approach certain has its limitations, but it's also pretty easy to implement: If you set the CData values on the border to be -Inf, those locations will always get the color at the "bottom" of the colormap (which is actually the first row). For example:
%%Generate some X, Y, and ZData
[X, Y] = meshgrid(linspace(-3, 3, 60));
Z = zeros(60);
border = true(60);
border(6:55, 6:55) = false;
Z(~border) = peaks(X(~border), Y(~border));
%%Make CData and plot
C = Z;
C(border) = -Inf;
surf(X, Y, Z, C);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by