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

조회 수: 5 (최근 30일)
Lieke Pullen
Lieke Pullen 2022년 1월 7일
댓글: Lieke Pullen 2022년 1월 9일
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 Performance에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by