... import data from a .txt file?

Hi there,

I have some .txt files with a large ammount of measuring Data, which i would want to draw in a XY-Graph. It is structured as follows:

1 15.0000 1.120000E+02
2 15.0003 1.460000E+02
3 15.0006 1.140000E+02
4 15.0008 1.340000E+02
5 15.0011 6.600000E+01
6 15.0014 1.100000E+02
7 15.0017 1.370000E+02
8 15.0019 6.000000E+01
9 15.0022 9.200000E+01
10 15.0025 5.200000E+01

and so on, till:

53197 39.9963 9.000000E+01
53198 39.9971 9.900000E+01
53199 39.9978 3.000000E+01
53200 39.9985 4.900000E+01
53201 39.9993 1.330000E+02

1st Column is just numbering through the measuring points. I wouldn't need to read this in. But if it ain't possible not to read it in, it wouldn't be hard then to eliminate this row in maple i guess.
2nd Column is be the Data for the X-Axis then
3rd Column is the Data for the Y-Axis.
(it is Detecting Ions in a Mass Spectrometer.. X=Molecule Mass, Y=Counts)

Can some1 tell me how i can read this File in?
I tried the ImportData(); asistant, but i couldn't manage to do the import.

I would be very very happy to get a Step by Step advise from one of you.
thx allready! :)

I just have seen, that the

I just have seen, that the copied and pasted text lost it's formation here in the post:

So the "Columns" are well structured, number under number - but it arent columns in the sense of a Excel file or something, its just a .txt file, with spaces inbetween.

I could also uload the file in the webb if some1 wants to try it for me.

readdata

Gernot,

Please see ?readdata.

Hope this helps.

J. Tarr

hi there, thx for

hi there, thx for answer,

Doesn't help that much yet ;). I allready found the Data Import assistant, but all the options i can choose there don't tell me uch, as i am not familiar with all this datatype stuff.

What i have is a normal .txt file. They are in a sort of ordered form. Between the 1st and the 2nd column there are 5 "spaces", between the 2nd and the 3rd there are 3 "spaces".
But thats all then.
But i allready tried to make a table out of it in Numbers (thats the analogon to Excel on a Mac). I couldn't find out how to devide it into 3 columns yet.. any1 knows?

Or maybe any1 knows that in Excel? I could use my Fathers PC for that then.

hi Mariner. didn't see your post at first. I will check that ?readdata thx!

readdata example

Gernot,

Here's an example of using readdata to read in part of your text file, assuming that its Windows path is C:\Maths\Maths11 and its name is example.txt

restart;
readdata("C:\\Maths\\Maths 11\\example.txt",[integer,float,float]);
 [[1, 15.0000, 112.0000], [2, 15.0003, 146.0000], [3, 15.0006, 114.0000],

   [4, 15.0008, 134.0000], [5, 15.0011, 66.00000], [6, 15.0014, 110.0000],

   [7, 15.0017, 137.0000], [8, 15.0019, 60.00000], [9, 15.0022, 92.00000],

   [10, 15.0025, 52.00000]]
 

Hope this helps

J. Tarr

hi Mariner, Yes, that helped

hi Mariner,

Yes, that helped a lot indeed! :D.
You are a genius! thx a lot!!

I have one more question: It seemed like when reading in the Data, it ignored the 1st Row of the Text file. How can i change this?
I could maybe make a fake Row in the Text file.

greets, Gernot

Text file

Gernot,

Without seeing your text file, I can only guess that the first row contains entries that don't fit the specification [integer,float,float] - see ?readdata. Perhaps the very first entry should be the integer 1 but has been entered with a stop or comma after the 1 which maple sees as a floating point number, and so it does not match the specification. Or, are there blanks preceeding the first entry?

Tidying up your  text file should solve the problem.

Good luck,

J. Tarr

Axel Vogt's picture

Say your data look like

Say your data look like this (with non-constant spacing, but 3 for each line):
 1   15.0000   1.120000E+02
2   15.0003    1.460000E+02
3 15.0006 1.140000E+02
4 15.0008 1.340000E+02
5 15.0011 6.600000E+01
6 15.0014 1.100000E+02
7 15.0017 1.370000E+02
8 15.0019 6.000000E+01
9   15.0022          9.200000E+01
10 15.0025 5.200000E+01
53197 39.9963 9.000000E+01
53198 39.9971 9.900000E+01
53199 39.9978 3.000000E+01
53200 39.9985 4.900000E+01
53201 39.9993 1.330000E+02
and that they are stored in a file data.txt.
Then you write
  fd := fopen(dataFile,READ,TEXT):
  theData:=readdata(fd, 3): # 3 columns
  fclose(fd):
These are 15 tuples:
nData:=nops(theData);
                             nData := 15
Showing them you can use 'print(theData)' or convert(theData, listlist), working with them
may be best by using 'convert(theData, Array)'  or 'convert(%,Array, (datatype = float[8]))'
lemelinm's picture

Cannot make it work!

Here is my *.txt file created in Excel

1    10,9    118,81
2    12    144
3    15    225
4    17,8    316,84
5    21,2    449,44
6    35,4    1253,16
 

The separator is the Tabulation.  When I want to import it in Maple, here is what I get:

> readdata("D://Data//Data6//Data_plot1.txt", float, 3);

[[1., 10.], [2., 12., 144.], [3., 15., 225.], [4., 17.], [5., 21.], [6., 35.]]

As you can see, even if I tell Maple that they are floating numbers and that there is 3 columns, I get that strange result.

Any ideas?

mario.lemelin@cgocable.ca

lemelinm's picture

Forget my preceding posting

My problem is that the Excel separate the decimal with a comma instead of a point.  Now I have been able to import with ImportData or readdata.  Sorry for the trouble.....

mario.lemelin@cgocable.ca

Axel Vogt's picture

language dependency

For the language dependency in Excel & Windows one either can
preprocess. Or temporarily changes settings. Or uses Maple:

  fd := fopen(dataFile,READ,TEXT):
    theData:=readdata(fd,string, 3): # 3 columns
  fclose(fd):

  A:=convert(theData,Array);

  map( t -> StringTools[SubstituteAll](t,",","."), A); 
  map(parse,%);

Which gives it for your given *.txt
lemelinm's picture

Wow! very nice....

Thanks.

mario.lemelin@cgocable.ca

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}