Azzera filtri
Azzera filtri

plot magnitude data at location (x,y,z)

69 visualizzazioni (ultimi 30 giorni)
Jorge
Jorge il 22 Ago 2024 alle 13:27
Commentato: Star Strider il 23 Ago 2024 alle 15:17
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

Risposta accettata

Star Strider
Star Strider il 22 Ago 2024 alle 19:21
@Jorge
Try this —
LD = load('data')
LD = struct with fields:
data: [201x4 double]
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
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
Cfcn = scatteredInterpolant(x, y, c, 'natural','none'); % Create Colour MAtrix
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
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 Commenti
Jorge
Jorge il 23 Ago 2024 alle 14:47
thanks for taking the time to explain!
Star Strider
Star Strider il 23 Ago 2024 alle 15:17
As always, my pleasure!
The purpose of MATLAB answers is to provide solutions, as well as education in various contexts.

Accedi per commentare.

Più risposte (1)

Aquatris
Aquatris il 22 Ago 2024 alle 13:34
Modificato: Aquatris il 22 Ago 2024 alle 13:37
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)
  2 Commenti
Jorge
Jorge il 22 Ago 2024 alle 19:04
Thank you for you input. That does give me something I can use, but I'm left wondering if there is yet a better way to display the data. Here's a sample of data I collected in the lab. The data has the coordinates of the x,y,z fixture, and the values measured. The format is [x,y,z,value]. if you think of a better, please let me know. I appreciate the help. Thank you.
Aquatris
Aquatris il 23 Ago 2024 alle 14:28
Modificato: Aquatris il 23 Ago 2024 alle 14:28
Here is similar scatter3 way with your code:
load('data.mat')
x = data(:,1);
y = data(:,2);
z = data(:,3);
m = data(:,4);
scatter3(x,y,z,100,m,'filled')
colorbar
view(-15,10)

Accedi per commentare.

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by