I am trying to transpose a matrix of size 3*2 by defining a empty matrix of size 2*3, how can i create an empty matrix?? I am missing something in the commented piece of code!!
type Row = List[Int]
type Matrix = List[Row]
val m:Matrix = List(1 :: 2 :: Nil, 3 :: 4 :: Nil, 5 :: 6 :: Nil)
def transpose(m:Matrix):Matrix = {
val rows = m.size
val cols = m.head.size
val trans= List(List())(rows(cols)) // Int doesn't take parameter
for (i <- 0 until cols) {
for (j <- 0 until rows) {
trans(i)(j) = this (j)(i)
}
}
return trans
}