How to create a 3D plot and split the values inside?

Let´s say I have 3 coordinates, x,y and z
x goes from 0 to 120 with a step of one
y goes from 0 to 200 with a step of one
z goes from -25 to 25
The values inside vary, for example:
vector = ( x, y , z)
2.5 = ( 10, 22, -5 )
How can I later make divisions on this data based on the value of the vector or values inside the entire matrix.
Something like the image above.

 Respuesta aceptada

darova
darova el 27 de Feb. de 2020
Use logical operations
id = vector > 2.5;
plot3(x(ix),y(ix),z(ix),'.r') % plot only points where vector > 2.5

12 comentarios

Mariana
Mariana el 1 de Mzo. de 2020
The problem is that the coordinate is not the one that defines te division of colors. The stored value inside the coordinate is the one that defines it.
darova
darova el 1 de Mzo. de 2020
Can you show your data? Formulas?
Sure.
data/data1/data2/data3/data4/data5 are my 2D tables
x goes from 0 to 120 with a step of one
y goes from 0 to 200 with a step of one
z is the third coordinate.
I will first read the value of z if it is between 0 and -5. Then I will use data1 instead of data.
%Input
y= 100;
x= 80;
z= -4;
%Conditions
if z >= 0
val = timegap(y,x,1);
disp(val);
if val > 2
disp('Save zone')
else
disp('Danger zone')
end
elseif (0>z) && (z>-5)
val = timegap(y,x,2);
disp(val);
if val > 2
disp('Save zone')
else
disp('Danger zone')
end
end
The value of z defines which 2d table I will use. I want to make a 3d plot so that I can show to people that the more negative my z value the values inside my 2D decrease.
Please let me know if I had explained myself
What about slice?
opengl software
load data_val.mat
[m,n,k] = size(timegap);
ii = 1:10:m;
jj = 1:10:n;
z = -4:1:10;
kk = (z>=0) + 2*((-5<z)&(z<0)); % 1 if z>=0, 2 if -5<z<0
val = timegap(ii,jj,kk); % choose values
% zone = val > 2;
[Y,X,Z] = ndgrid(ii,jj,z);
cla
xslice = [25 80];
yslice = [20 180];
zslice = [-2 8];
h = slice(X,Y,Z,val,xslice,yslice,zslice); % create volume slices
set(h,'edgecolor','none')
alpha(0.3) % make slice transparent
for zone = [0.1 2 15]
isosurface(X,Y,Z,val,zone); % create zones
end
colorbar
axis vis3d
xlabel('X')
ylabel('Z')
zlabel('Z')
Result
Mariana
Mariana el 1 de Mzo. de 2020
Editada: Mariana el 1 de Mzo. de 2020
I need to plot all the values inside the 6 2D tables and then split into two sections. When the value inside that coordinate is higher than 2 is green if it is less than 2 then it should be red.
Change these lines
kk = 1:6;
val = timegap(ii,jj,kk); % choose values
[Y,X,Z] = ndgrid(ii,jj,kk);
And add these
ival = val > 2;
hold on
plot3(X(ival),Y(ival),Z(ival),'.g','markersize',15)
plot3(X(~ival),Y(~ival),Z(~ival),'.r','markersize',15)
hold off
result
opengl software
load data_val.mat
[m,n,k] = size(timegap);
ii = 1:10:m;
jj = 1:10:n;
z = -4:1:10;
kk = 1:6;
val = timegap(ii,jj,kk); % choose values
[Y,X,Z] = ndgrid(ii,jj,kk);
cla
xslice = [25 80];
yslice = [20 180];
zslice = [-2 8];
h = slice(X,Y,Z,val,xslice,yslice,zslice); % create volume slices
set(h,'edgecolor','none')
alpha(0.3) % make slice transparent
for zone = [0.1 2 15]
isosurface(X,Y,Z,val,zone); % create zones
end
colorbar
axis vis3d
xlabel('X')
ylabel('Y')
zlabel('Z')
ival = val > 2;
hold on
plot3(X(ival),Y(ival),Z(ival),'.g','markersize',15)
plot3(X(~ival),Y(~ival),Z(~ival),'.r','markersize',15)
hold off
I am not getting the same result as you did. Where is my mistake?
darova
darova el 2 de Mzo. de 2020
Mariana
Mariana el 16 de Mzo. de 2020
Is it possible to get rid of the slides?
darova
darova el 16 de Mzo. de 2020
Of course. Get rid of them
Mariana
Mariana el 16 de Mzo. de 2020
How can I create a function based on the created plane?
darova
darova el 16 de Mzo. de 2020
Can you be more specific? What plane? Show it on the picture

Iniciar sesión para comentar.

Más respuestas (1)

Mariana
Mariana el 16 de Mzo. de 2020

1 comentario

Sure. Use scatteredInterpolant
p = isosurface(X,Y,Z,val,2);
xx = p.vertices(:,1);
yy = p.vertices(:,2);
zz = p.vertices(:,3);
patch(p,'facecolor','b','edgecolor','none')
F = scatteredInterpolant(yy,zz,xx); % Function of a plane (Y,Z)
Example of using
x1 = F(90,4)
plot3(x1,90,4,'oy')
Result

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Performance en Centro de ayuda y File Exchange.

Productos

Versión

R2018b

Etiquetas

Preguntada:

el 27 de Feb. de 2020

Comentada:

el 16 de Mzo. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by