Hi,

Am Donnerstag, 18. Okt 2007, 01:03:21 +0900 schrieb baptiste Augui=E9:
>> angle          value1            value2
>> 156.00        3.3688E-03        1.7040E-03
>> 157.00        3.2919E-03        1.7118E-03
>> 158.00        3.2140E-03        1.7190E-03
>> 159.00        3.1354E-03        1.7258E-03
>> 160.00        3.0560E-03        1.7320E-03
>> 161.00        2.9760E-03        1.7378E-03
>> 162.00        2.8956E-03        1.7431E-03
>> 163.00        2.8148E-03        1.7479E-03
>> 164.00        2.7338E-03        1.7523E-03
>> 165.00        2.6526E-03        1.7562E-03
>> 166.00        2.5714E-03        1.7597E-03
>> 167.00        2.4902E-03        1.7628E-03
>
> I would like to extract the 3 columns of data for several consecutive lin=
es=20
> (say, from angle =3D 158 to 165). These values should be stored in some a=
rray=20
> or vector. How can I do that in Ruby?

Anybody considered ranges?

  r =3D 158..165
  file.each { |l|
    ang, val1, val2 =3D l.split.map { |x| Float x }
    r =3D=3D=3D ang and do_sth_with val1, val2
  }

  r =3D 158..165
  file.each { |l|
    ang, val1, val2 =3D l.split.map { |x| Float x }
    case ang
      when r then do_sth_with val1, val2
    end
  }

Does anybody remember flip-flops?

  file.each { |l|
    ang, val1, val2 =3D l.split.map { |x| Float x }
    iang =3D ang.floor
    if (iang=3D=3D158)..(iang=3D=3D165) then
      do_sth_with val1, val2
    end
  }

The floor call is not actually beautiful here but always
keep in mind equality shouldn't be tested for floats.
Flip-flops need equality.

Bertram


--=20
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de