【问题标题】:Surface plot with highligheted cut带有高亮切割的曲面图
【发布时间】:2015-06-01 13:35:15
【问题描述】:

我想使用 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

任何帮助将不胜感激!

【问题讨论】:

  • 对冲浪图使用“保持”的问题是重叠不是逐层完成的(如您所想),这通常会产生较差的结果。我认为最好的方法实际上是进行后期处理,生成图形,然后去 Photoshop 之类的工具中进行替换颜色选项。

标签: matlab matlab-figure


【解决方案1】:

似乎没有办法使用不同的colormap 来获得所需的效果,因为颜色图“属于”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

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-02
    • 1970-01-01
    • 2010-12-26
    • 2014-04-14
    • 1970-01-01
    • 2017-10-31
    • 2014-05-03
    • 1970-01-01
    相关资源
    最近更新 更多