I have an m by n matrix 'A' full of real values. I need to find the line integral along a line y=mx+b through the matrix. I'm having trouble doing this without for loops. Currently I am creating a zero matrix 'B', then looping through the X indices, solving for the Y index, and setting B(x,y) = 1. I then do an element wise multiplication of A and B and sum the elements of the result. ex. sum(sum(A.*B))
This is a horribly inefficient way of doing things but I can't figure out how to do it quicker. I can easily create arrays of the x,y values that correspond to the line but don't know how to pairwise reference those elements alone.