Plot 3D Vectors in arrows

From Computational Biophysics and Materials Science Group
Jump to: navigation, search
Unsym-fn-100-hold.gif

Here is a matlab code for creating 3D plots of vectors in terms of arrows.

In fact it has been modified to read periodically a number of lines (28 in this case) from the input data file (six columns coorx, coory, coorz, vecx, vecy, vecz) and makes a 3D plot in terms of red arrows.

In addition, the second half of the code, still within the for loop, is making an animation in gif from all the plots. Enjoy.

filename='unsym_outf_fn-100.dat';
outname='unsym-fn-100-hold.gif';
figure
for i=1 28 2800
    k=i+27;
    dlmstr=['A',num2str(i),'..F',num2str(k)];
    data=dlmread(filename,' ',dlmstr);
    %figure
    quiver3(data( ,1),data( ,2),data( ,3),data( ,4),data( ,5),data( ,6),'r');
    fn=k/28;
    tstr=['Frame ',num2str(fn)];
    title(tstr);
    hold on
    axis ([-30 40 -20 10 30 60])
    view(-48,24)
    hold off
    
    drawnow
    frame = getframe(1);
    im = frame2im(frame);
	[A,map] = rgb2ind(im,256); 
        if i == 1;
            imwrite(A,map,outname,'gif','LoopCount',Inf,'DelayTime',0.2);
        else
            imwrite(A,map,outname,'gif','WriteMode','append','DelayTime',0.2);
        end
end