How to do the 3D vector plot from dataset?

조회 수: 6 (최근 30일)
Nanthanon Visitpongaree
Nanthanon Visitpongaree 2019년 2월 21일
댓글: Cris LaPierre 2020년 8월 4일
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