Tag Archives: Mathematica

It’s great to automatically save an output at the end of a script. It is sometimes desirable to run the script multiple times, saving the data under a new filename. It’s simple to generate new filenames using the date etc. If the script were to be used regularly by multiple people, with different file naming tastes, it maybe useful to use a dialog box to export data. This avoids people screwing with your script to add different filenames and can be done using a single line of code

I find matrices in Mathematica to be a little tricky. They are not strictly matrices, more like lists of lists. Here is a short example of manipulation of a 3d matrix. If we have a file of image data representing multiple images (i.e. multiple 2d matrices) we can manipulate them using the Map function. So for a set of data as follows

we use Map[Image[#,”byte”]&, data]to get

Where the function Image represents each element in the data file as a pixel, with the option “byte” specifying the data format and # representing the function argument (in this case # = data).

Exporting graphics – To export a plot assign a variable to the plot; for example graph1=ListPlot[c], and then export using Export[“filename.jpg”,graph1] to save the plot as a jpeg, with the chosen file name, in whichever folder is set as default in Mathematica’s properties (to set the target directory type SetDirectory[“dir”]).

Disclaimer – Since I am a true newbie the information given here is not likely to be the most efficient way of achieving things with Mathematica. I would definitely appreciate comments and corrections.

Like this:

I was still struggling with the lists business when I came across a different way to display them. If we have two lists a and b where a={1,2,3} and b={4,5,6} we can create the matrix c={a,b}. Mathematica views this as a list of lists and the output is as follows; c={{1,2,3},{4,5,6}}. I find this a little uncomfortable to look at when dealing with larger amounts of data. MatrixForm[c] will give an output which (to me) looks much more clear.

Disclaimer – Since I am a true newbie the information given here is not likely to be the most efficient way of achieving things with Mathematica. I would definitely appreciate comments and corrections.