Demonstration of matlab mesh() function function (verified)

【Function】Draw three-dimensional surface grid diagram. The biggest advantage of the three-dimensional surface grid map is that it can better solve the problem of data visualization in three-dimensional space.
[Syntax] mesh( z ), z is the function to be drawn.
The sample code is as follows:

x=-8:0.5:8;
y=x';
X=ones(size(y))*x;
Y=y*ones(size(x));
R=sqrt(X.*X+Y.*Y);
z=sin(R)./R;
mesh(z)    %大家只需了解mesh()的效果就行,不用纠结上面代码

 

 

Multiple mesh images are displayed in different colors 

close all
clear
clc
[x,y] = meshgrid(-pi:0.1:pi);
A1 = 0.5*sin(1)-2*cos(1)+sin(2)-1.5*cos(2);
A2 = 1.5*sin(1)-cos(1)+2*sin(2)-0.5*cos(2);
B1 =0.5.*sin(x)-2.*cos(x)+sin(y)-1.5.*cos(y);
B2 = 1.5.*sin(x)-cos(x)+2.*sin(y)-0.5.*cos(y);
f1 = 1+(A1-B1).^2+(A2-B2).^2;
f2 =(x+3).^2+(y+1).^2;
figure(1)
mesh(x,y,f1,'edgecolor','r','linewidth',0.5)
hold on
mesh(x,y,f2,'edgecolor','g','linewidth',0.5)
xlabel('x'),ylabel('y'),zlabel('f')
legend('f1','f2')

 

colourbar

1.caxis([cmin cmax])

It is used to control the upper and lower boundaries of the colorbar. By controlling the boundaries, each subgraph can use the same range of colorbars. By default, when the Control Colorbar function is not used, the color is filled in sequence according to the size of the function value. For custom cases, it needs to be set manually. This is what the blogger’s colleague asked today. The default is basically enough under normal circumstances. used.

clear all

clc

subplot(2,1,1)

[x y]=meshgrid(-1:0.01:1);

f=x.^2+y.^2;

mesh(x,y,f)

colorbar

caxis([0 4])

subplot(2,1,2)

[x y]=meshgrid(-1:0.01:1);

f=x.^2+y.^2+2;

mesh(x,y,f)

colorbar

caxis([0 4])

 

 

 

2. In the above example, we keep the colorbars of the two subgraphs consistent. At this time, another problem arises.

Since the colorbars of the two images are the same, why don't we merge them into one? We put the colorbar uniformly into two

On the right side of the graph, it is necessary to control the size and position of the subgraph at this time.

clear all

clc

h1=subplot(2,1,1);

% get(h1,'Position')

set(h1,'Position',[0.2    0.6    0.5    0.35])

[x y]=meshgrid(-1:0.01:1);

f=x.^2+y.^2;

mesh(x,y,f)

h=colorbar;

% get(h, 'Position')

set(h,'Position',[0.8    0.1    0.05    0.8])

caxis([0 4])

h2=subplot(2,1,2);

% get(h2,'Position')

set(h2,'Position',[0.2    0.1    0.5    0.35])

[x y]=meshgrid(-1:0.01:1);

f=x.^2+y.^2+2;

mesh(x,y,f)

% colorbar

% caxis([0 4])

 

Guess you like

Origin blog.csdn.net/Vertira/article/details/130734945