- #1
PhDeezNutz
- 796
- 553
- TL;DR Summary
- I eventually want to create a vector addition graphic in matlab. As in the literal "head to tail" idea.
Here is my code thus far and it seems to work (I've attached a gif as well so hopefully that works)
What I want to avoid doing is copying and pasting the last part of the last if block for each new else or elseif statement.
If I want to add to eventually add say 30 things to the animation then I will have to copy the last parts 30 times.How do I get around this?
Notice i had to replot "quiver1" for the "else" statement. I would hate to do this endlessly for successive parts.
Anyway I would appreciate any advice about how to approach this and here's the gif.
Wow that gif is slow.
Matlab:
va1 = [50*cos(pi/3), 50*sin(pi/3)]; %Two different vectors both starting from the origin
vb1 = [20*cos(pi/6), 20*sin(pi/6)];
iterator = linspace(1,100,100); %100 iterations for the animation inside the for loop
vaiteratorx = linspace(0,50*cos(pi/3),100); % The ending x points for the first vector in successive animations
vaiteratory = linspace(0,50*sin(pi/3),100); % The ending y points for the first vector in successive animations
vbiteratorx = linspace(0,20*cos(pi/6),100); % The ending x points for the second vector in successive animations
vbiteratory = linspace(0,20*sin(pi/6),100); % The ending y points for the second vector
for i = 1:length(iterator)
clf
if i <=50
initial_point1 = [0,0];
dp = [2*vaiteratorx(i) 2*vaiteratory(i)];
q1 = quiver(0,0,2*vaiteratorx(i),2*vaiteratory(i),0,'color','m','linewidth',3,'MaxHeadSize',0.25);
hold on
else
q1 = quiver(0,0,vaiteratorx(end),vaiteratory(end),0,'color','m','linewidth',3,'MaxHeadSize',0.25);
hold on
initial_point2 = [0,0];
dp2 = [2*vbiteratorx(i-50) 2*vbiteratory(i-50)];
q2 = quiver(0,0,dp2(1),dp2(2),0,'color','c','linewidth',3,'MaxHeadSize',50*0.25/20);
hold on
end
xlim([0 200])
ylim([0 ceil(9*200/16)]);
set(gca,'color','k');
set(gcf,'color','k');
Ax = gca;
Ax.XAxis.Visible = 'off';
Ax.YAxis.Visible = 'off';
Ax.XGrid = 'off';
Ax.YGrid = 'off';
Ax.Color = 'none';
fig=gcf;
fig.Units='normalized';
fig.OuterPosition=[0 0 1 1];
movieVector(i) = getframe(gcf)
end
myWriter = VideoWriter('SlideTwo','MPEG-4');
myWriter.FrameRate = 1;
open(myWriter)
writeVideo(myWriter,movieVector)
close(myWriter)
What I want to avoid doing is copying and pasting the last part of the last if block for each new else or elseif statement.
If I want to add to eventually add say 30 things to the animation then I will have to copy the last parts 30 times.How do I get around this?
Notice i had to replot "quiver1" for the "else" statement. I would hate to do this endlessly for successive parts.
Anyway I would appreciate any advice about how to approach this and here's the gif.
Wow that gif is slow.