I have written a function:
func Pic(dx, dy int) [][]uint8 {
type matrix [][]uint8
for i := 0; i < dx; i++ { // fills up the matrix with z's in their right places.
for j := 0; j < dy; j++ {
matrix[i][j] = Z(i,j)
}
}
return matrix
}
that is supposed to fill up a matrix with z values for each x and y value and return it. As I want to have different dimensions for the matrix depending of parameters to the Pic function, I create a slice i line 2. Then in my for loops i fill the matrix up.
I get an error upon running this code: type matrix is not an expression
for the matrix[i][j] = Z(i,j)
line. What am I doing wrong? Should matrix[i][j] evaluate to an expression? Why should it, when I want to put something there (it's empty/non-existent now!) ?
You're declaring matrix
as a type, but using it as a variable.
try:
var matrix [][]uint8
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With