Hi fellow Matlab coders,
I wonder if there is any way to get rid of at least the inner loop by using matrix notation (what I mean by using matrix notation is like eg. 'for i = j, A(i) = B(i) -1, end' can be replaced by 'A(j) = B(j) - 1' and similar) ?
A and B are constructed in a way that elements in 'data' that are written are not read
for i = 1:size(A,1)
s = 0;
for j = 1:size(B,2)
ind = A(i,:)' + B(:,j)
s = s + data(ind(1),ind(2));
end
data(A(i,1),A(i,2)) = data(A(i,1),A(i,2)) + s;
end
What the code does is a stencil (here with values allways 1) looping over two-dimensional 'data'.
B gives shape of the stencil, A the elements in 'data' to be processed.
I am thinking if converting to a one-dimensional array for data could help/make sence?
Thanks a lot for any help,
Matthias