带有高亮切割的曲面图
Surface plot with highligheted cut
我想使用 Matlab surf
函数绘制 3D 表面。整个表面应该是灰度的,然后我需要使用不同的颜色突出显示表面的特定切割。
我以为这段代码会起作用,但它不起作用。
Mat = randi(100); % Matrix to be plotted in gray scale
ind_highlight = 10; % Row of the matrix to be highlighted
Mat2 = Mat;
Mat2([1:ind_highlight-1, ind_highlight+1:end] ,:) = NaN;
figure
surf(X,Y,Mat)
colormap gray
hold on
% Highlight the ind_highlight row
surf(X,Y,Mat2)
colormap hsv
非常感谢任何帮助!
似乎没有办法使用不同的 colormap
来获得所需的效果,因为颜色映射 "belongs" 到 figure
。
我找到了一个不使用 colormap
的可行解决方案。
基于在调用surf
时指定颜色矩阵,一个是整个矩阵,一个是要高亮的部分,然后将第二个叠加到第一个上。
很遗憾,我无法将第一个广告设置为灰色。
我使用了 peaks
矩阵而不是您的“randi
”,以便使用更光滑的表面并将脚本插入 for loop
以突出显示矩阵的不同部分
% Mat = randi(100,100,100); % Matrix to be plotted in gray scale
% Alternative definition of the Matrix to be displayed
n_pt=50;
Mat=peaks(n_pt);
% Generate meshgrid
x=1:n_pt;
y=1:n_pt;
[X,Y]=meshgrid(x,y);
ind_highlight_2 = 5; % Number of rows of the matrix to be highlighted
% Generate two set of color matrix
% The first on for the whole surf
% The second one for the section to be highlighted
a=randi(2,n_pt,n_pt);
b=randi(10,n_pt,n_pt);
for i=1:n_pt-ind_highlight_2
ind_highlight_1 = i; % Starting row of the matrix to be highlighted
Mat2 = Mat;
% Modified set of data (in the original just one row was left
% Mat2([1:ind_highlight-1, ind_highlight+1:end] ,:) = NaN
Mat2(ind_highlight_1:ind_highlight_1+ind_highlight_2,:) = NaN;
COL=a;
COL(ind_highlight_1:ind_highlight_1+ind_highlight_2,:)=b(ind_highlight_1:ind_highlight_1+ind_highlight_2,:);
% Plot the surf specifying the color
s_h=surf(X,Y,Mat,COL);
shading interp
% view([0 90])
% f_name=['jpg_name_' num2str(i)]
% print('-djpeg75',f_name)
pause(.1);
end
希望对您有所帮助。
我想使用 Matlab surf
函数绘制 3D 表面。整个表面应该是灰度的,然后我需要使用不同的颜色突出显示表面的特定切割。
我以为这段代码会起作用,但它不起作用。
Mat = randi(100); % Matrix to be plotted in gray scale
ind_highlight = 10; % Row of the matrix to be highlighted
Mat2 = Mat;
Mat2([1:ind_highlight-1, ind_highlight+1:end] ,:) = NaN;
figure
surf(X,Y,Mat)
colormap gray
hold on
% Highlight the ind_highlight row
surf(X,Y,Mat2)
colormap hsv
非常感谢任何帮助!
似乎没有办法使用不同的 colormap
来获得所需的效果,因为颜色映射 "belongs" 到 figure
。
我找到了一个不使用 colormap
的可行解决方案。
基于在调用surf
时指定颜色矩阵,一个是整个矩阵,一个是要高亮的部分,然后将第二个叠加到第一个上。
很遗憾,我无法将第一个广告设置为灰色。
我使用了 peaks
矩阵而不是您的“randi
”,以便使用更光滑的表面并将脚本插入 for loop
以突出显示矩阵的不同部分
% Mat = randi(100,100,100); % Matrix to be plotted in gray scale
% Alternative definition of the Matrix to be displayed
n_pt=50;
Mat=peaks(n_pt);
% Generate meshgrid
x=1:n_pt;
y=1:n_pt;
[X,Y]=meshgrid(x,y);
ind_highlight_2 = 5; % Number of rows of the matrix to be highlighted
% Generate two set of color matrix
% The first on for the whole surf
% The second one for the section to be highlighted
a=randi(2,n_pt,n_pt);
b=randi(10,n_pt,n_pt);
for i=1:n_pt-ind_highlight_2
ind_highlight_1 = i; % Starting row of the matrix to be highlighted
Mat2 = Mat;
% Modified set of data (in the original just one row was left
% Mat2([1:ind_highlight-1, ind_highlight+1:end] ,:) = NaN
Mat2(ind_highlight_1:ind_highlight_1+ind_highlight_2,:) = NaN;
COL=a;
COL(ind_highlight_1:ind_highlight_1+ind_highlight_2,:)=b(ind_highlight_1:ind_highlight_1+ind_highlight_2,:);
% Plot the surf specifying the color
s_h=surf(X,Y,Mat,COL);
shading interp
% view([0 90])
% f_name=['jpg_name_' num2str(i)]
% print('-djpeg75',f_name)
pause(.1);
end
希望对您有所帮助。