Friday, July 10, 2009

on md

Well, I am using dlpoly to get my molecular dynamics simulations done and I can
say that it is not an easy task. Errors happen all the time and for some strange reason
I am getting too high diffusivity numbers... I hope I can resolve this enough though.
More details coming.

Wednesday, July 8, 2009

data files to image to video using Matlab

The other day I was given 800 XY data files created through a set of measurements with Labview
and I had to convert them into a video...

So I found some code for images to video from here:
http://nw360.blogspot.com/2007_05_01_archive.html
and I already had an idea on how to make the data files into plots/images.

So here is the code I used in two m files. If u find any error or find an easier way notify me!

datatoimg.m ::

function varout=datatoimg(ext, imdir, filename)

%usage: datatoimg('dat', '/Users/alex/Documents/MATLAB/files/temp', '*');

%if you find any errors ask me

%Athens: 8-7-09

warning('datatoimg:warning','Do NOT close or open any window during the process!\n')

filearray=dir([imdir filesep '*.' ext])

numfiles=size(filearray,1)

cd (imdir);

for i=1:1:numfiles

[x, y] = textread(filearray(i).name, '%f %f');

currentPlot = plot(x, y);

title(i);

axis([350 800 -50 250])

saveas(currentPlot,[filearray(i).name,'.jpg'],'jpg');

clear currentPlot;

end

im2avi('jpg', '', 1, 1, 'myOutput', 0, filearray);


imgtoavi.m ::

function varargout=im2avi(ext, imdir, scale, framerate, filename, playflag, directory)

% im2avi converts image sequenses to avi video

%

% SYNTAX

%

% Inputs: imdir: image sequense directory

% ext: the extension name of the image such as 'jpg', 'tif',

% scale: image resize, like [320 400] or 0.9

% framerate: avi video frame rate

% filename: save avi as

% playflag: play the avi video; if it is 0, no play, if >0,

% play the avi 'playflag' times.

%

% EXAMPLE: im2avi(ext, imdir, scale, framerate, filename, playflag)

%

% NOTES: based on im2avi (author: Zhe Wu @ Univ of Rochester)

% Wenbin, 09-May-2007

warning('im2avi:warning','Do NOT close or open any image window during the process!\n')

filearray=dir([directory filesep '*.' ext]);

s=size(filearray,1);

frameind=0;

mv =struct('cdata',{}, 'colormap', {});

figure, h =gcf;

for i=1:s

frameind=frameind+1;

imgname=[filearray(i).name];

im=imread(imgname) ;

im=imresize(im, scale);

imshow(im);

mv(frameind)=getframe(h);

end

close(h)

movie2avi(mv, [directory filesep filename '.avi'], 'fps', framerate);

if nargout >0

varargout{1} =mv;

end

if playflag>0

movie(mv, playflag);

end

Hello World!

Well, let's begin.