Hi, I got a question to figure out the largest sum of n consecutive elements in a matrix. The order can be in the same row, column, diagonal, or reverse diagonal. Here is my code. However, the matlab keeps telling me variables "i","j", "u", "w","z" may be unused.Could you give me a hint how to make these variables valid? Also, I guess there is a way to simply my code a little bit? Thanks!
A numerical example would be: Suppose A=[1 2; 3 4] and n=2. We need to find the largest sum of 2 consecutive elements in all directions. In this case, we have
rows: 1+2, 3+4
columns: 1+3, 2+4
reverse diagonal: 2+3
Obviously, the output of this function should be 3+4. How could I write a function without loops? Any hint will be appreciated.
for i =1:p
x=max([M T Y K]);