Four-dimensional mapping:
This problem can be achieved with the slice command:
%%%=================================%%%
Clear All
[x, Y, z] = Meshgrid (0:.5:10,0:.5:10,0:.5:10);
c = x.^2+y.^2+z.^2;
xs = [0,2,4,6,8,10];
YS = [4];
ZS = [6]; % Xs,ys,zs can determine the form and position of the slice, Helpslice can understand its specific meaning
Slice (X,y,z,c,xs,ys,zs)
ColorMap HSV
Of course, as long as Doc Surf, you will find, in fact, the surf command has its own color command:
A simple example is as follows (the color vector looks at the actual problem can be changed to represent the function value):
%%%=================%%%
Clear All
[X,y]=meshgrid (0:.5:10);
c = rand (21);
z=x^2-5*x.*y+y.^2;
Surf (X,Y,Z,C);
[x, Y, z] = Meshgrid ( -2:.2:2, -2:.25:2, -2:.16:2);
v = x. * EXP (-x.^2-y.^2-z.^2);
Slice (x,y,z,v,[-1.2.8 2],2,[-2-.2])
Functional three-dimensional slicing chart. This command displays a rectangular slice of the image through a stereo shape.
Usage Slice (X,Y,Z,V,SX,SY,SZ) shows several points in the x-axis, y-axis, and z-axis direction (corresponding to several planes) of the super-vertical shape determined by the ternary function v=v (x, Y, z). Even if function v=v (x, Y, z) has a variable, such as a certain value X0, the function v=v (x0,y,z) becomes a solid surface (except that the surface is represented by a color of height V, thus appearing in a plane. ), the coordinates of each point are specified by the parametric vector sx, SY, and Sz. parameter x, parameter y, and parameter z are three-dimensional arrays that specify the coordinates of the cube v. The parameters x, y, and Z must have a monotonic, orthogonal interval (as generated by the command Meshgrid). The color at each point is determined by the three-dimensional interpolation of the super-stereoscopic v.
Slice (V,SX,SY,SZ) shows a slice of the x-axis, y-axis, and z-axis points (corresponding to several planes) of the super-vertical shape determined by the ternary function v=v (z/y), and the coordinates of each point are specified by the quantity vector sx, sy, and Sz. Where V is a three-dimensional array (order of m*n*p), by default: x= 1:m, Y = 1:n, Z = 1:p.
Slice (V,xi,yi,zi) shows the sectional view of the super-stereoscopic graph of the parametric matrix XI, YI and ZI. The Parametric XI, Yi, and Zi define a surface, and the value of hyper-Stereoscopic V is computed at the point of the surface. The parameter xi, Yi and Zi must be the same type matrix.
Slice (X,y,z,v,xi,yi,zi) travels along a slice of the hyper-stereoscopic graph V, defined by the matrix XI, YI, and ZI.
Slice (..., ' method ') specifies the interpolation method. ' Method ' is one of the following methods: ' Linear ',
' Cubic ', ' nearest ':
' Linear '--Specifies the use of a three-time linear interpolation method (which is the default);
' Cubic '--Specifies the use of three cubic interpolation methods;
' Nearest '--specifies that the nearest point interpolation method is used.
h = Slice (...) returns the handle vector h of a curved graphic object.
>>x=[1 2 3 4 5 6]; >> y=[1 2 3 4 5 6]; >> z=[3 5 6 7 8 9]; >> [X1,y1,z1]=meshgrid (x, y, z); >> s=x1+y1+z1; >> Slice (x1,y1,z1,s,1,2,8) Get the following figure, I want to express is s=x+y+z, corresponding to 6 XYZ should only 6 s how to have a corresponding z-value in each slice of the graph, thank you |
Slice (x1,y1,z1,s,[],[],z)
can achieve only 6 Z of the slice diagram
Try each of the following three commands:
>> Slice (x1,y1,z1,sk,[],[],s)
>> Slice (x1,y1,z1,sk,x,[],s)
>> Slice (x1,y1,z1,sk,x,y,s)
can meet the requirements
######################################################################################################
For the following data, make sectional view, and set the data according to the corresponding color value;
X y z S
1 2 2 25
1 3 3 21
1 4 4 20
2 5 5 19
2 6 7 31
Such a group of S and X, Y, z do not have direct function expression relationship with the data hope to be able to use the slice function to plot the slice plot, that is, in x=1 this aspect, there should be corresponding s=25 21 20 of these three color-represented function values.
First, you see an example in the Help file for the slice command:
[x, Y, z] = Meshgrid ( -2:.2:2,-2:.25:2,-2:.16:2);
v = x.*exp (-x.^2-y.^2-z.^2);
Xslice = [ -1.2,.8,2]; Yslice = 2; Zslice = [ -2,0];
Slice (X,y,z,v,xslice,yslice,zslice)
ColorMap HSV
Here the slice first three parameters, must constitute the grid data, as shown:
Pass:
[x, Y, z] = Meshgrid ( -2:.2:2,-2:.25:2,-2:.16:2);
Figure
View (3);
Hold on;
For i = 1:size (x, 1)
for j = 1:size (x, 2)
For k = 1:size (x, 3)
PLOT3 (x (i, J, K), Y (i, J, K), Z (i, J, K), '. ');
End
End
End
These points form the grid data
Therefore, we need to make the grid data, the section operation;
Close all;
CLC
Clear
A = [1 2 2 25
1 3 3 21
1 4 4 20
2 5 5 19
2 6 7 31];
x = A (:, 1) ';
y = A (:, 2) ';
z = A (:, 3) ';
s = A (:, 4) ';
% Extract Valid data
XB = min (x);
XE = max (x);
YB = min (y);
Ye = max (y);
ZB = min (z);
Ze = max (z);
SB = min (s);
SE = max (s);
X1 = linspace (XB, XE, 30);
Y1 = Linspace (Yb, ye, 30);
Z1 = Linspace (ZB, ze, 30);
S0 = Linspace (SB, SE, 30);
% of effective data segmentation
[x1 y1 Z1] = Meshgrid (x1, Y1, Z1);
% generate grid data points
S1 = zeros (Size (x1, 1), Size (x1, 2));
For i = 1:size (S1, 1)
S1 (i,:) = S0;
End
st = Zeros (Size (x1, 1), Size (x1, 2), Size (x1, 3));
For i = 1:size (St, 3)
St (:,:, i) = S1;
End
S1 = st;
% structured four-dimensional data s1
Figure
Hold on;
View (3);
Slice (x1, y1, Z1, S1, X, [], []);
So we're going to make the so-called section diagram.
This is done by slice (x1, y1, Z1, S1, X, y, []), but without the color value setting option;
Close all;
CLC
Clear
A = [1 2 2 25
1 3 3 21
1 4 4 20
2 5 5 19
2 6 7 31];
x = A (:, 1) ';
y = A (:, 2) ';
z = A (:, 3) ';
s = A (:, 4) ';
% of effective data segmentation
XB = min (x);
XE = max (x);
YB = min (y);
Ye = max (y);
ZB = min (z);
Ze = max (z);
Y1 = Linspace (Yb, ye, 30);
Z1 = Linspace (ZB, ze, 30);
X1 = ones (Size (Y1, 1), Size (Y1, 2)) * x (1);
[x1, y1] = Meshgrid (x1, y1);
z = zeros (length (z1));
For i = 1:size (z, 1)
Z (i,:) = z1;
End
Surf (x1, y1, z);
% This time produced a mesh section corresponding to the X1, the following to set the color
[A, b] = size (z);
RGB = Ones (A, b);
Len = Length (s) +1;
Slic = Floor (linspace (1, A, Len));
For i = 1:length (slic)-1
RGB (Slic (i): Slic (i+1)-1,:) = RGB (Slic (i): Slic (i+1)-1,:) *s (i);
End
% produces color values
Figure
Surf (x1, y1, z, RGB);
This is a color-setting figure.