anne001 <anne / wjh.harvard.edu> wrote:
> 
> Question 2:
> -----------------
> Once I have a 2D array, what is the best way to find the index of the
> key word Trial (which starts the data I want).
> 
> In matlab, I would do something like,
> Find the index pair (I,J) at which Array = Trial
> If J==1
> Extract the array starting at row I+1 to I+82, for columns [2, 3, and
> 5]
> and I would love some pointers at Ruby structures, methods, etc I need
> to look at. 

This should get you started:

#------------------------------------------------

ary = [
  ["this", "is", "some", "code"],
  ["test", "please", "ignore"],
  ["Trial", "section", "begins", "here"],
  ["foo", "bar", "baz", "quux"]
]

index = nil
searchterm = "Trial"
catch(:done) do
  ary.each_with_index {|row, i|
    row.each_with_index {|cell, j|
      puts "testing [#{i},#{j}]"
      if cell =~ /^#{searchterm}/
        index = [i,j]
        throw :done
      end
    }
  }
end

puts "-----------------"

puts "found #{searchterm} at #{index.inspect}"

#------------------------------------------------

martin