MATLAB Answers

0

How to do the 3D vector plot from dataset?

Latest activity Answered by Cris LaPierre on 9 Apr 2019
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

  0 Comments

Sign in to comment.

1 Answer

Answer by Cris LaPierre on 9 Apr 2019

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.

  0 Comments

Sign in to comment.