How to do the 3D vector plot from dataset?

6 次查看(过去 30 天)
I want to plot like (picture) this but I don't know what I did wrong with my code. Using the data set in excel file (in the attachment).
In Excel file, The first 3 columns are the position in x, y, z axes and the last 3 columns are the magnetic field in x, y, z axes as Bx, By and Bz.
Each arrows that shown in the 3D graph are the magnitude of magnetic field :
MagB = sqrt(Bx^2+By^2+Bz^2)
Thank you very.
clear all;
close all;
L1 = xlsread('11x11x11 in 3D.xlsx');
N1=11;
N2=11;
N3=11;
l = 1;
for i = 1 : 1 : N1
for j = 1 : 1: N2
for k = 1 : 1 : N3
l = (i-1)*N2*N3+((j-1)*N3+k);
X(k,j,i) = L1(k, 1);
Y(k,j,i) = L1(k, 2);
Z(k,j,i) = L1(k, 3);
X1(k,j,i) = L1(k, 4);
Y1(k,j,i) = L1(k, 5);
Z1(k,j,i) = L1(k, 6);
end
end
end
quiver3(X,Y,Z,X1,Y1,Z1)
11.PNG

回答(1 个)

Cris LaPierre
Cris LaPierre 2019-4-9
Here's the code that will load and plot the data.
opts = detectImportOptions("11x11x11 in 3D.xlsx");
opts.VariableNames = {'X','Y','Z','Bx','By','Bz'};
data = readtable('11x11x11 in 3D.xlsx',opts);
quiver3(data.X,data.Y,data.Z,data.Bx,data.By,data.Bz)
I don't know what you are trying to do with your code. The plot you get with my code will not look like the image you've shared. You should take a look at your data if you don't understand why.
  2 个评论
Daynah Rodriguez
Daynah Rodriguez 2020-8-4
编辑:Daynah Rodriguez 2020-8-4
Hey Cris,
I used this same code to plot Jupiter's magnetic field (Bx,By,Bz) from Juno's XYZ position. Is this a correct representation of it?
Cris LaPierre
Cris LaPierre 2020-8-4
I can't see anything wrong with your plot, but I do not have enough background in the magnetic fields of Jupiter to be able to tell you if it is correct or not.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Vector Fields 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by