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.

 採用された回答

darova
darova 2020 年 2 月 27 日

0 投票

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

12 件のコメント

Mariana
Mariana 2020 年 3 月 1 日
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 2020 年 3 月 1 日
Can you show your data? Formulas?
Mariana
Mariana 2020 年 3 月 1 日
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
darova
darova 2020 年 3 月 1 日
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 2020 年 3 月 1 日
編集済み: Mariana 2020 年 3 月 1 日
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.
darova
darova 2020 年 3 月 1 日
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
Mariana
Mariana 2020 年 3 月 2 日
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 2020 年 3 月 2 日
Mariana
Mariana 2020 年 3 月 16 日
Is it possible to get rid of the slides?
darova
darova 2020 年 3 月 16 日
Of course. Get rid of them
Mariana
Mariana 2020 年 3 月 16 日
How can I create a function based on the created plane?
darova
darova 2020 年 3 月 16 日
Can you be more specific? What plane? Show it on the picture

サインインしてコメントする。

その他の回答 (1 件)

Mariana
Mariana 2020 年 3 月 16 日

0 投票

1 件のコメント

darova
darova 2020 年 3 月 16 日
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

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

製品

リリース

R2018b

質問済み:

2020 年 2 月 27 日

コメント済み:

2020 年 3 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by