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!
0 个评论
采纳的回答
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);
for L = Levels
isosurface(XQ, YQ, ZQ, SQ, L);
end
3 个评论
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);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!