MathGroup Archive 2010

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

Search the Archive

Re: for loop outside a do cicle

On 4/12/10 at 6:52 AM, mariagiovannadainotti at (maria giovanna
dainotti) wrote:

>Dear Mathgroup, thanks a lot for your help with the joint table. I
>have now a question regarding the loops

>if I have a table DataGood built in such a way DataGood={};
>DataBad={}; Do[ Ta=DataFit[[i,10]]; Lx=DataFit[[i,12]];
>uTa=DataFit[[i,11]]; uLa=DataFit[[i,13]]; u=(uTa^2+uLa^2)^1/2;
>idGRB=DataFit[[i,9]]; z=DataFit[[i,8]]; Eiso=DataFit[[i,3]];
>Lumprompt=DataFit[[i,5]]; If

>If I would like to vary u=0.095 up to 4 with a step of 0.010 in
>order to have different tables because then I should compute
>Correlation coefficient amomg Eiso and Lx how can I do? I mean how
>can I put the for cicle outside or inside this loop

I would do this as follows:

=46irst set u to a list of all radii using Norm as:

u = Norm /@ DataFit[[All, {11, 13}]];

Next format the desired output array

toRetain =
    Flatten@{#1[[{10 ;; 13}]], #2, #1[[{9, 8, 3,
          5}]]} &, {DataFit, u}];

=46inally, use Table and Pick to separate good/bad

data = Table[{Pick[toRetain, u, _?(# < limit &)],
    Pick[toRetain, u, _?(# >= limit &)]}, {limit, .095, 4, .01}]

Note, I've eliminated use of Do and AppendTo. For large data
sets, AppendTo will consume significant resources and should not
be used. Table is much more efficient at creating an array than
appending one item at a time to an existing array with AppendTo.

I've also set the body of the Table to create both the good/bad
data lists for each value of limit at the same time. While this
is efficient, an alternative that might result in a more
convenient output would be:

DataGood = Table[Pick[toRetain, u, _?(# < limit &)], {limit,
.095, 4, .01}];
DataBad = Complement[toRTetain, #]&/@DataGood;

  • Prev by Date: Selecting subscripted variables from an expression
  • Next by Date: Re: Root again
  • Previous by thread: for loop outside a do cicle
  • Next by thread: .swf export and hyperlinking