How do I make a 3D plot with assigned values?

19 次查看(过去 30 天)
Hi all,
I am trying to plot a 3D mesh grid based on the x, y and z coordinates and an assigned value. Each coordinate has its own value, and thus I would like to plot the values assigned to that coordinate. My code is the following:
Svalues=readmatrix('s_values.csv');
xs=Svalues(:,1);
ys=Svalues(:,2);
zs=Svalues(:,3);
s=Svalues(:,4);
figure;
points=length(xs);
for n=1:points
scatter3(xs(n),ys(n),zs(n),s(n));
hold on
end
It is probably varily easy, but I do not seem to get it right. Can anybody help me out?
Furthermore, the coordinates are symmetrical in 3D, and I would also like to plot that into a matrix (or so), so that I can multiply it with other matrices. Any tips on how to do that? Thanks in advance!

采纳的回答

Walter Roberson
Walter Roberson 2022-1-7
Svalues = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/856420/s_values.csv')
Svalues = 216×4
0 0 0 1.6100 0 0 1.0000 0.2760 0 0 2.0000 0.0226 0 0 3.0000 0.0013 0 0 4.0000 0.0000 0 0 5.0000 0.0000 0 1.0000 0 0.2760 0 1.0000 1.0000 0.0976 0 1.0000 2.0000 0.0128 0 1.0000 3.0000 0.0008
xs=Svalues(:,1);
ys=Svalues(:,2);
zs=Svalues(:,3);
s=Svalues(:,4);
N = 100;
xmin = min(xs); xmax = max(xs);
ymin = min(ys); ymax = max(ys);
zmin = min(zs); zmax = max(zs);
[XQ, YQ, ZQ] = meshgrid(linspace(xmin, xmax, N), linspace(ymin, ymax, N), linspace(zmin, zmax, N));
F = scatteredInterpolant(xs, ys, zs, s);
SQ = F(XQ, YQ, ZQ);
Levels = linspace(min(SQ(:)), max(SQ(:)), 12);
for L = Levels
isosurface(XQ, YQ, ZQ, SQ, L);
end
  3 个评论
Walter Roberson
Walter Roberson 2022-1-7
Svalues = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/856420/s_values.csv');
xs = Svalues(:,1);
ys = Svalues(:,2);
zs = Svalues(:,3);
s = Svalues(:,4);
N = 100;
xmin = min(xs); xmax = max(xs);
ymin = min(ys); ymax = max(ys);
zmin = min(zs); zmax = max(zs);
[XQ, YQ, ZQ] = meshgrid(linspace(xmin, xmax, N), linspace(ymin, ymax, N), linspace(zmin, zmax, N));
F = scatteredInterpolant(xs, ys, zs, s);
SQ = F(XQ, YQ, ZQ);
Levels = linspace(min(SQ(:)), max(SQ(:)), 12);
Levels = Levels(2:end-1);
M = [
-1 -1 -1;
-1 -1 1;
-1 1 -1;
-1 1 1;
1 -1 -1;
1 -1 1;
1 1 -1;
1 1 1;
];
for L = Levels
for K = 1 : size(M,1)
isosurface(XQ*M(K,1), YQ*M(K,2), ZQ*M(K,3), SQ, L);
end
end
set(findobj(gca, 'type', 'patch'), 'FaceAlpha', 0.3);
Lieke Pullen
Lieke Pullen 2022-1-9
Thank you very much! This is what I was looking for.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by