0
votes

I'd like to know if there is any more efficient way to do the following in matlab

[K, L] = meshgrid(1:sh,1:sv);
for i = 1 : sv
    for j = 1 : sh
        M = score_mat_temp + a*((K-j).*(K-j) + b*(K-j)) + c*((L-i).*(L-i) + d*(L-i)) + e;
    end
end

Because it is ultra slow right now with sv and sh typically of the order of 500

thanks a lot !

1
a b c d and e are all constants - user3188068
Do you want the size of M to be sv-by-sh, or do you want it like you have it here? - Stewie Griffin
... or score_mat_temp = score_mat_temp + a*...? Or else, your question doesn't make much sense... - Stewie Griffin

1 Answers

0
votes

All except the final value of M are simply overwritten. So calculating them is a waste. Use

[K, L] = meshgrid(1:sh,1:sv);
i = sv;
j = sh;
M = score_mat_temp + a*((K-j).*(K-j) + b*(K-j)) + c*((L-i).*(L-i) + d*(L-i)) + e;