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.

 Risposta accettata

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

12 Commenti

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.
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 il 1 Mar 2020
Modificato: Mariana il 1 Mar 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?
Is it possible to get rid of the slides?
Of course. Get rid of them
How can I create a function based on the created plane?
Can you be more specific? What plane? Show it on the picture

Accedi per commentare.

Più risposte (1)

Mariana
Mariana il 16 Mar 2020

1 Commento

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

Accedi per commentare.

Categorie

Scopri di più su Graphics Performance in Centro assistenza e File Exchange

Prodotti

Release

R2018b

Richiesto:

il 27 Feb 2020

Commentato:

il 16 Mar 2020

Community Treasure Hunt

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

Start Hunting!

Translated by