How do I make a 3D plot with assigned values?
9 views (last 30 days)
Show older comments
Lieke Pullen
on 7 Jan 2022
Commented: Lieke Pullen
on 9 Jan 2022
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 Comments
Accepted Answer
Walter Roberson
on 7 Jan 2022
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 Comments
Walter Roberson
on 7 Jan 2022
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);
More Answers (0)
See Also
Categories
Find more on Graphics Object Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!