Allen J. Hall

Materials Science & Engineering, Productivity, and Life

Monthly Archives: June 2009

MATLAB and reciprocal space mapping – small update.

Well, I’m one of those guys who believes a picture is usually worth a ton of words. I’ve got a few images to share here on the matlab code I’ve been working on for reciprocal space mapping in MATLAB. I’m still not 100% on my code right now, so I’m not sharing it for the time-being. In particular, I use an import function for .x00 slices for two-axis scans in the Panalytical/Philips XPert system. If you are using XRDML, skip the files for .x00 import that I have in other posts on this blog. In anycase, without much explanation here are the images…

Latex Hint: Use your computer leverage to output large amounts of data.

After a few weeks of doing cryogenic cathodoluminescence spectroscopy on some of my samples, I have gobs and gobs of spectra to look over, and the task is a bit daunting.  Oh sure, you can do so on the computer in many different ways, but often, I need to see my data on the page (old school) before I can really sort through it.  Sometimes even then there’s just too much of it and playing with the data in MatLab all together is critical.

Here’s what I came up with to help output my data very quickly into a printable document that included numerous graphs.  First, the primary goal of this quick method is to be quick- to get tons of graphics (of same proportions) into a doc for printing or perusing.  Second- it should be relatively minimal typing, if possible.  [We all know we can do it by hand 100x; while grad-student pay rate is low, there's gotta be a better way.]

1. Get a directory listing for all the items wanted to be included and dump this in a text file.  (ls *.pdf > filelist.tex)
2. Create a main.tex file which includes the code we’ll need to do this fast.  [You can reuse this file for other directories of graphics needed to be printed.]  My example uses the following:
\documentclass[%
,secnumarabic%
\usepackage[pdftex]{color,graphicx,rotating}
\setkeys{Gin}{width=0.85\columnwidth}

%Simple way to call images and add filenames to captions - for lots of data.
\newcommand{\dataimg}[1]{
\includegraphics[width=3in]{#1}
Filename: #1

}

\begin{document}
\title{CL Results\\
\textit{Internal document not for distribution.}}
\date{\today}
\author{Allen Hall}
\maketitle

\include{filenames}

\printfigures
\end{document}

The important code is the “\include{}” line and also the “\newcommand{\dataimg}…” section. This is what is going to do all the work for us.

3. Now, we need to take your filelist and add at the beginning of each line and end of each line the following:
\dataimg{

and at the end:

}

One way to do this simply is with a command line gawk command:

Terminal Prompt> ls |awk '{ print "\\dataimg{"\$0"}" }'
4. So, now each line looks like: \dataimg{filename1.pdf}
5. Once that is done, you can run the LaTeX compile, and you’ll have your file of graphs!  That’s a heck of a lot easier than writing each line out by hand.  [Use a program like TextMate or Gawk etc. to append and prepend each line with the necessary call.]

The benefit of the \newcommand is that it fills in the needed formatting for each graphics file, and attaches the filename for each graphic beside the graphics file itself.  You can make it prettier, I’m sure, but this is what I was able to do in a very short time frame.

There are many ways to accomplish this little task, you could use Gawk itself to write the latex file for you, I’ve seen some do makefiles to do this type of thing, or perl, or bash shell scripting etc.  But, the critical part is to leverage the computer to output a latex file for typsetting and save yourself some time.

A Quick Introduction...

I'm a graduate student (PhD Candidate) at the University of Illinois at Urbana-Champaign.

I've studied and researched in two fields of Materials Science and Engineering (Polymers and Semiconductors). My interests are as diverse as my musical tastes and I usually have my hand in some crazy project during my free time.