Making an animation of a 3d vector through time.
44 views (last 30 days)
Show older comments
I am relatively new to matlab and figuring this out alone is a little above my paygrade.
I put an accelerometer on a weather balloon for a project. The accelerometer gives an X, Y, and Z component of the actual acceleration vector.
rawdata=xlsread('balloon.xlsx'); %Importing Data
time=rawdata(:,7);
Zaccel=rawdata(:,2);
Yaccel=rawdata(:,4);
Xaccel=rawdata(:,6);
resultant=rawdata(:,8);
for i=1:length(resultant) %Correcting for Outliers
if resultant(i)>5
resultant(i)=0;
elseif resultant(i)<1
resultant(i)=0;
end
end
for j=1:length(Zaccel) %Correcting for Outliers
if Zaccel(i)<1
Zaccel(i)=0
elseif Zaccel(i)>5
Zaccel(i)=0
elseif Yaccel(i)<1
Yaccel(i)=0
elseif Yaccel(i)>5
Yaccel(i)=0
elseif Xaccel(i)<1
Xaccel(i)=0
elseif Xaccel(i)>5
Xaccel(i)=0
end
end
unitx=[]; %Creating X-componant of unit vector
for i=1:length(Xaccel)
unitx(i)=Xaccel(i)./resultant(i);
end
unity=[]; %Creating Y-componant of unit vector
for j=1:length(Yaccel)
unity(j)=Yaccel(j)./resultant(j);
end
unitz=[]; %Creating Z-componant of unit vector
for k=1:length(Zaccel)
unitz(k)=Zaccel(k)./resultant(k);
end
curve=animatedline('Linewidth',2);
figure
for i=1:length(unitx)
addpoints(curve, unitx(i), unity(i), unitz(i));
drawnow
end
I want to make an animation of the direction that this unit vector points through time so that each time step, the plot displays the next vector. So in essence, instead of plotting a bunch of points over time, I want each "point" to be a vector arrow pointing from the origin and I do not want them to stay plotted, I want each to be deleted as the next is plotted. I am not sure how to go about this.
Zaccel, Yaccel, and Xaccel represent the raw data given by the accelerometer. Resultant is the magnitude of the resultant vector.
0 Comments
Accepted Answer
KSSV
on 4 Dec 2017
N = 100 ;
%%coordinate positions
X = rand(N,1) ;
Y = rand(N,1) ;
Z = rand(N,1) ;
%%Velocity components
u = rand(N,1) ;
v = rand(N,1) ;
w = rand(N,1) ;
for i = 1:N
quiver3(X(i),Y(i),Z(i),u(i),v(i),w(i)) ;
pause(0.1) ;
end
2 Comments
manar ahmed
on 4 Mar 2020
If I have a structure like a rectangular waveguide or any structure and I want to plot an animated 2d field vector at every section in a way that looks smooth like in this website, is there anything you could suggest?
More Answers (0)
See Also
Categories
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!