plot magnitude data at location (x,y,z)
24 次查看(过去 30 天)
显示 更早的评论
I can't figure out how to plot magnitudes of a variable at different (x,y,z) locations. In effect, I need to plot a 4D plot, (x,y,z,value). I thought I'd be able to do a 3D plot and set the 4D as color scale or something like that, but I can't figure how to do that.
Perhaps I'm over thinking this....but, I'd appreciate any help.
Thanks!
Jorge
0 个评论
采纳的回答
Star Strider
2024-8-22
@Jorge —
Try this —
LD = load('data')
x = LD.data(:,1);
y = LD.data(:,2);
z = LD.data(:,3);
c = LD.data(:,4);
figure
stem3(x, y, z)
hold on
scatter3(x, y, z, 100, c, 'filled')
hold off
CL = clim;
colormap(turbo)
xlabel('X')
ylabel('Y')
zlabel('Z')
view(130,30)
Zfcn = scatteredInterpolant(x, y, z, 'natural','none'); % Create Surface Matrix
Cfcn = scatteredInterpolant(x, y, c, 'natural','none'); % Create Colour MAtrix
N = numel(x);
xv = linspace(min(x), max(x), N);
yv = linspace(min(y), max(y), N);
[Xm,Ym] = ndgrid(xv, yv);
Zm = Zfcn(Xm, Ym);
Cm = Cfcn(Xm, Ym);
figure
surfc(Xm, Ym, Zm, Cm, 'EdgeColor','interp')
clim(CL)
colormap(turbo)
xlabel('X')
ylabel('Y')
zlabel('Z')
view(130,30)
The only change from my previous answer was using your data. Some parts do not interpolate well and leave gaps, however that appears to be inhereint in your data, at least as far as scatteredInterpolant interprets them.
.
13 个评论
Star Strider
2024-8-23
As always, my pleasure!
The purpose of MATLAB answers is to provide solutions, as well as education in various contexts.
更多回答(1 个)
Aquatris
2024-8-22
编辑:Aquatris
2024-8-22
Here is one way where you use colors to indicate the magnitude;
% random data
x = [0:pi/50:10*pi nan]; % nan is added to remove connection between first and last data point
y = sin(x);
z = cos(x);
m = x; % magnitude you want as colors, i set it to x cause it looks nice :D
colormap(winter)
patch(x,y,z,m,'Facecolor','none','EdgeColor','interp')
colorbar
view(3)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!