How to improve performance in a function that repeatedly defines and multiplies matrices

The outcome of the line g = im*tr(W\X) + (transpose(W\V)*X*(W\V))[1] - (transpose(Y)*(W\V))[1] is a 1x1 matrix. So I assumed writing g[1] would not be a problem. As it seemed like I am essentially converting a Matrix of dimensions (1,1) to a number.

1 Like