Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > matrix: exchange rows + exchange columns

Reply
Thread Tools

matrix: exchange rows + exchange columns

 
 
Alessandro Barracco
Guest
Posts: n/a
 
      01-25-2011
Hi all, I wrote two new method for exchange 2 row (2 columns) in a
matrix:


class Matrix
def exchange_rows(i,j)
a = Matrix.rows(@rows) # matrice originale
b = a.clone() # matrice di servizio
for k in 0...a.column_size
a[i,k] = b[j,k]
a[j,k] = b[i,k]
end
return a
end

def exchange_columns(i,j)
a = Matrix.rows(@rows) # matrice originale
b = a.clone() # matrice di servizio
for k in 0...a.row_size
a[k,i] = b[k,j]
a[k,j] = b[k,i]
end
return a
end


I hope it is usefull to you....

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hide the Gridview Rows and Header rows in Button click VijayRama ASP .Net 2 10-12-2009 01:58 PM
Rows the rows of a grid view? Jason James ASP .Net 0 08-10-2006 09:24 PM
dynamically add new rows and save data typed in these rows to a database Arjen Hoekstra ASP .Net 0 08-02-2005 12:15 PM
convert rows to columns and columns to rows helpful sql ASP .Net 0 05-19-2005 06:03 PM
script for moving rows up and down and traverse thru rows of HTML table Subba Rao via DotNetMonster.com ASP .Net 0 03-19-2005 06:46 AM



Advertisments