--1926193751-2060514707-1192728797=:19231
Content-Type: MULTIPART/MIXED; BOUNDARY="1926193751-2060514707-1192728797=:19231"
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
--1926193751-2060514707-1192728797=:19231
Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE
Hi --
On Thu, 18 Oct 2007, Phrogz wrote:
> On Oct 17, 10:03 am, baptiste Augui=E9 <ba...@exeter.ac.uk> wrote:
>>> 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
>> lines (say, from angle =3D 158 to 165). These values should be stored
>> in some array or vector. How can I do that in Ruby?
>
> # Make an array of arrays of numbers
> # based on scanning for non-whitespace characters
> # (all strings will show up as 0.0)
> values =3D IO.readlines( 'input.dat' ).map{ |line|
> line.scan( /\S+/ ).map{ |str| str.to_f }
> }
Or:
require 'scanf'
values =3D IO.readlines('input.dat').map {|line| line.scanf("%f%f%f") }
(Assuming the > at the beginning isn't really part of it -- otherwise
">%f%f%f".)
I'm not entering the speed contest

but scanf might be nice for the
conversions.
David
--=20
Upcoming training from Ruby Power and Light, LLC:
* Intro to Ruby on Rails, Edison, NJ, October 23-26
* Advancing with Rails, Edison, NJ, November 6-9
Both taught by David A. Black.
See
http://www.rubypal.com for more info!
--1926193751-2060514707-1192728797=:19231--
--1926193751-2060514707-1192728797=:19231--