Message Boards Message Boards

6 Replies
0 Total Likes
View groups...
Share this post:

Reading from multiple data files

I want to program Mathematica 9 to read the coordinates (x,y,z) of a given object (which is characterized by a 7 digit number) from multiple files and make a plot. Is there a way to do this?

POSTED BY: Nilanjan Banik
6 Replies

Hello David,

Thank you so much for your reply. To give specifics of my files and what I want to do, I am doing simulations with dark matter haloes from redshift 30 to 20 and trying to track the haloes with mass > 10^6 Msun. My simulation generates catalogs at a given redshift (Z), from Z= 30 to 20 with a redshift jump of 0.1. Each of these catalogs (in .dat) are named with their redshift and contains halo ID (a unique 7 digit number to specify each halo), their position (x,y,z), so there are in total 4 columns.

With Mathematica, I want to make three plots Z vs x, Z vs y and Z vs z to track the history of each halo since the time they were born. I know about the import option, and also the chart bubble option (which might help in designating a specific colored bubble for each halo, so that we may identify them).

My idea so far is to add a fifth column in the data files with redshift, and then import column 4 (halo ID) as a list to a variable "i", such that i1, i2, i_3 .... are the first halo id, the second halo id and so on. Then to import the coordinates as usual and then to use bubble chart option based on the variable "i" to plot redshift vs x and redshift vs y and so on..

POSTED BY: Nilanjan Banik

HI Nilanjan,

What is difficult about your question is that your are describing your files in general terms but not actually explaining their exact format. What you are asking for is completely doable but the details depend on the exact format of your data. Without that there isn't a way for someone to tell you what specific code to write to complete your task. Do you have a different file for each time? And, if so, then does each such file have two columns: redshift and position? And also, if so, is the time specified in the file's name or is it somehow in the file itself?

In any case it will help to give you some answers if you either (a) give a detailed specification of the files and the filenames and/or (b) give a set of example files.

I'm sure we'd all like to help, but we need your help with the actual details ;-)

Best, David

POSTED BY: David Reiss

Thank you for your reply. I do know about the * wildcard, but what I don't know is how do I get Mathematica to plot the points of a given object from all these files. I am trying to get Mathematica to look for a given object whose ID is say 3456789, whose position is changing with time (redshift in my case) and to plot their position. The various files that I have stores the positions of these objects at a given redshift. I am trying to make 3 plots time vs X, time vs Y and time vs Z for the objects.


POSTED BY: Nilanjan Banik


You can use * wildcard to import all files:

SetDirectory[NotebookDirectory[]] ;
(* export test files *)
Export["eg01.dat",1] ;
Export["eg02.dat",2] ;
Export["eg03.dat",3] ;
Export["eg10.dat",10] ;
(* import all test files *)


POSTED BY: Ivan Morozov

The data are in .xsls format. However how do you get Mathematica to open multiple files whose names have a pattern like example. 01, example. 02 and so on.

POSTED BY: Nilanjan Banik

There most likely is. What is the format of your files?

The function for you to read about is Import:

POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract