plotting a multivariable function by colors
1 次查看(过去 30 天)
显示 更早的评论
Hello.
I want to plot this picture bot I don't know what command to useand how.
0 个评论
回答(1 个)
Rik
2019-8-18
编辑:Rik
2019-8-21
You can use the surf function (and set the view so you look from above), or use ind2rgb to apply a colormap.
Edit:
The code below should give you an idea of how to get your desired result.
%retrieve the x,y,z information from the surf
f=openfig('1.fig');
ax=findobj(get(f,'Children'),'type','axes');
S=findobj(get(ax,'Children'),'type','Surface');
x=get(S,'XData');
y=get(S,'YData');
z=get(S,'ZData');
z_backup=z;
close all%close all currently opened figures (use only during debugging)
%% option 1: using surf
%replace inf and -inf by edge values for a more pretty plot
z(isinf(z) & z>0)=max(z(~isinf(z)));
z(isinf(z) & z<0)=min(z(~isinf(z)));
figure
surf(x,y,z,'EdgeColor','none')
view(0,90)
axis([min(x) max(x) min(y) max(y)])
%% option 2: using ind2rgb
%define a colormap
map=colormap('hot');
z=z_backup;%restore z
%scale z-data so it is an indexed image
L=~( isinf(z(:)) | isnan(z(:)) );
range=[min(z(L)) max(z(L))];
z=(z-range(1))/(range(2)-range(1));
z=ceil(z*size(map,1));
IM=ind2rgb(z,map);
IM=rot90(IM,2);%account for different directional convention
%show image
figure
imshow(IM)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Blue 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!