- #1

- 47

- 0

## Main Question or Discussion Point

Hi,

Is there a way to associate each element with its row and column number without explicitly doing each one in turn? I have a matrix and I want to multiply it by a matrix whose elements are a function which takes as its input values the row and column number of the first matrix.

(I think essentially I'm trying to treat the matrix as a grid of coordinates).

What I'm trying to do is to say,

new_matrix(a,b) = old_matrix(a,b) * f(a,b)

where a and b are the row and column number.

My problem is I don't know how to tell matlab that I want a to be the row number and b to be the column number. My current idea is to create two matrices, one with all the column values equal and incrementing by 1, and the other the same but with row values equal, and treat these as x and y matrices, but this seems like a rather long-winded way of doing it. Can anyone help? (I'm new to matlab so it's probably something really obvious!)

Is there a way to associate each element with its row and column number without explicitly doing each one in turn? I have a matrix and I want to multiply it by a matrix whose elements are a function which takes as its input values the row and column number of the first matrix.

(I think essentially I'm trying to treat the matrix as a grid of coordinates).

What I'm trying to do is to say,

new_matrix(a,b) = old_matrix(a,b) * f(a,b)

where a and b are the row and column number.

My problem is I don't know how to tell matlab that I want a to be the row number and b to be the column number. My current idea is to create two matrices, one with all the column values equal and incrementing by 1, and the other the same but with row values equal, and treat these as x and y matrices, but this seems like a rather long-winded way of doing it. Can anyone help? (I'm new to matlab so it's probably something really obvious!)