Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

I: Re: importing series of file with the same extension

  • To: mathgroup at smc.vnet.net
  • Subject: [mg124851] I: Re: importing series of file with the same extension
  • From: maria giovanna dainotti <mariagiovannadainotti at yahoo.it>
  • Date: Thu, 9 Feb 2012 05:40:48 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

--- Gio 9/2/12, maria giovanna dainotti <mariagiovannadainotti at yahoo.it> has escritto:

Da: maria giovanna dainotti <mariagiovannadainotti at yahoo.it>
Oggetto: Re: importing series of file with the same extension
A: "Bob Hanlon" <hanlonr357 at gmail.com>
Data: Gioved=EC 9 febbraio 2012, 03:28

Dear Bob,
thanks a lot for your suggestion. It works,but when I put the expression in a loop it doesn't work anymore

I am reporting here the loop

Do[
 grbid = If[NumericQ[ToExpression[#]], "0" <> ToString[#], #] & /@
   grbs;
 Data456 = Import[# <> ".txt", "Table"] & /@ grbid[[bb]];
       GRB = {};
 GRBtot = {};
 GRByerr = {};
 GRByerrUL = {};
 GRByerrorTot = {};
 Do[
  row = Data456[[i]];
  time = Data456[[i, 3]];
  flux = Data456[[i, 15]];
  errTimePos = Data456[[i,=0A 3]];
  errTimeNeg = Data456[[i, 2]];
  errFlux = Data456[[i, 16]];
  symTimeErr = (errTimePos - errTimeNeg)/2*1.65;
 =0A (*LogSymTimeError=Log[10,time+symTimeErr]-Log[10,time];*)
  If[errFlux > 0, dlogSymTFluxError = errFlux/(flux*Log[10])];
  (*If[errFlux==0,
  dlogSymTFluxErrorUL=1/(2*Log[10])];*)
  AppendTo[GRB, {Log[10, time], Log[10, flux]}];
  AppendTo[GRByerrorTot, {dlogSymTFluxError(*,dlogSymTFluxErrorUL*)}];
  AppendTo[GRBtot, {{GRB}, ErrorBar[GRByerrorTot]}],
  {i, 1, Length[Data456]}];
 (*Plots of whole LC and the selected parts:*)
        p1 =
  ErrorListPlot[GRBtot, PlotRange -> Full, Frame -> True,
   Axes -> False, RotateLabel -> True, PlotStyle -> Black,
   PlotLabel -> grbid <> " NEW"]  , {bb, 1, Length[grbs]}]

I mean I have a file for every grbs and I would like to perform computation on each single file.

Thanks again,
Best regards,
Maria


--- Mar=0A 7/2/12, Bob Hanlon <hanlonr357 at gmail.com> ha scritto:

Da: Bob Hanlon <hanlonr357 at gmail.com>
Oggetto: Re: importing series of file with the same extension
A: "maria giovanna dainotti" <mariagiovannadainotti at yahoo.it>
Cc: mathgroup at smc.vnet.net
Data: Marted=EC 7 febbraio 2012, 16:57

grbs = {"80825593", "80916009", "81006604", "81024891", "81224887",
   "90217206", "90227772", "90323002", "90328401", "90510016", "90531775",
   "90626189", "90720710", "90902462", "90926181", "91003191", "91031500",
   "100116897", "100225115", "100325275", "100414097", "100620119",
   "100724029", "100728095", "100826957", "101014175", "101123952",
   "101204343", "110120666", "110328520", "110428388", "110529034",
   "110625881", "110709642", "110721200", "110731465"};

grid = Table[grbs[[bb]], {bb, 1, Length[grbs]}];

This doesn't accomplish anything since

grid == grbs

True

You defined grbs with strings so none of its elements are numeric. To
test whether the elements could be converted to numeric you would use
NumericQ[ToExpression[_]]. And, since they are already strings you
wouldn't need ToString. However, if you want to handle either strings
or numbers you can do both.

You need to Map your function onto the elements of your list

grbid = If[NumericQ[ToExpression[#]], "0" <> ToString[#], #] & /@ grbs;

Import[# <> ".txt", "Table"] & /@ grbid


Bob Hanlon


On Tue, Feb 7, 2012 at 4:02 AM, maria giovanna dainotti
<mariagiovannadainotti at yahoo.it> wrote:
> Dear Mathematica group,
> I have defined the following=0A code:
>
> grbs = {"80825593", "80916009", "81006604", "81024891", "81224887",
>  "90217206", "90227772", "90323002", "90328401", "90510016",
>  "90531775", "90626189", "90720710", "90902462", "90926181",
>  "91003191", "91031500", "100116897", "100225115", "100325275",
>  "100414097", "100620119", "100724029", "100728095", "100826957",
>  "101014175", "101123952", "101204343", "110120666", "110328520",
>  "110428388", "110529034", "110625881", "110709642", "110721200",
>  "110731465"}
>
> grid = Table[grbs[[bb]], {bb, 1, Length[grbs]}]
> If[NumericQ[grid], GRBID = "0" <> ToString[grid], GRBID = grid]
>
> Data = Import[GRBID <> ".txt", "Table"]
>
> When I use this last command to import the data file not found during import.
>
> The name of the data files are 080825593.txt etc
> It gives error=0A anyway also if I change the grbs putting 080825593.
> I would be very grateful if you could help me.
>
> Best regards,
> Maria



--
Bob Hanlon


  • Prev by Date: Re: PDE with RecurrenceTable
  • Next by Date: Re: Dancing "a la Levenberg-Marquardt" to get the best Logistic Model.
  • Previous by thread: Using ./ - having trouble understanding why it isn't more like a 'map' function
  • Next by thread: Mathematica has quit unexpectedly