From: Victor Reyes Date: 2007-10-29T07:54:37+09:00 Subject: Re: How do I define a dynamic Matrix or .... ------=_Part_6060_20463750.1193612079374 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Many thanks to Thomas and 7stud! I will try your suggestions! Thanks again Victor On 10/28/07, 7stud -- wrote: > > Victor Reyes wrote: > > ..I need to be > > able to define my matrix dynamically and on demand. > > Can anyone tell me how to do that? > > > > Try this: > > #get input: > print 'rows: ' > rows = Integer(gets) > print 'columns: ' > cols = Integer(gets) > > > #create matrix: > matrix = [] > rows.times do |i| > matrix << Array.new(cols, 0) > end > > p matrix > > > Or this: > > require 'matrix' > > print "size: " > size = Integer(gets) > > m = Matrix.zero(size) > p m > -- > Posted via http://www.ruby-forum.com/. > > ------=_Part_6060_20463750.1193612079374--