Surf function with interp: symmetric surface shown assymmetrically

3 ビュー (過去 30 日間)
kandaz
kandaz 2018 年 11 月 17 日
コメント済み: kandaz 2018 年 11 月 18 日
Hello All,
I have a surface Z formed by the following commands (very simplified version) and it is symmetric in XY plane (looking from the top or bottom). However when I use the "surf" command with 'interp', I get a slightly assymetric surface.
clc
clear all
Z=[0 0.1 0.3 0.1 0;
0 0.2198 0.4432532 0.2198 0;
0 0.4242 0.7898989 0.4242 0;
0 0.2198 0.4432532 0.2198 0;
0 0.1 0.3 0.1 0];
[X,Y] = meshgrid(0:1.5:6,0:1.5:6);
surf(X, Y, Z, 'LineStyle', '-', 'FaceColor', 'interp')
daspect([1,1,0.2])
colormap(jet)
colorbar
When I use decimal numbers instead of the Z values above though, I do not get such a problem.
Any ideas how to obtain the symmetric surface at XY plane?
Cheers.
  2 件のコメント
Bruno Luong
Bruno Luong 2018 年 11 月 17 日
IMO Parula does not releal defect as clear as JET (which I still prefer in general)
nonsym.png

サインインしてコメントする。

採用された回答

Bruno Luong
Bruno Luong 2018 年 11 月 17 日
編集済み: Bruno Luong 2018 年 11 月 17 日
The color interpolation carried out by MATLAB is not symetric by values but also by order. This induces the defect.
To trick MATLAB you have te reorganize the data
Z=[0 0.1 0.3 0.1 0;
0 0.2198 0.4432532 0.2198 0;
0 0.4242 0.7898989 0.4242 0;
0 0.2198 0.4432532 0.2198 0;
0 0.1 0.3 0.1 0];
[X,Y] = meshgrid(0:1.5:6,0:1.5:6);
x = linspace(-1,1,size(Z,2));
y = linspace(-1,1,size(Z,1));
close all
hold on
for k=1:4
if k<=2
ix = find(x>=0);
else
ix = flip(find(x<=0));
end
if mod(k,2)==0
iy = find(y>=0);
else
iy = flip(find(y<=0));
end
surf(X(iy,ix), Y(iy,ix), Z(iy,ix), 'LineStyle', '-', 'FaceColor', 'interp')
end
daspect([1,1,0.2])
colormap(jet)
colorbar
Defect coloring when using single SURF command
  1 件のコメント
kandaz
kandaz 2018 年 11 月 18 日
Wow thanks a lot Bruno! This saved me from a lot of trouble.
Cheers.

サインインしてコメントする。

その他の回答 (1 件)

madhan ravi
madhan ravi 2018 年 11 月 17 日

カテゴリ

Help Center および File ExchangeColormaps についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by