sparse indexing in matlab <p>I have a very long code which is full of the following "if"s and matlab editor gives me a suggestion as follow:</p> <p><strong>this sparse indexing expression is likely to be slow</strong></p> <pre><code>mt = rand(200,200); [c r] = size(mt); T = sparse(r*c,2); for i = 1:c for j = 1:r if(ind(j,i)==1) templat = template + 1; T((i-1)*r+j,2)=100000; end end; end; </code></pre> <p>Is there any way by which I can make the code faster and do the matlab's suggestion? (The code may not run, because I just picked a few lines and tried to show the issue)</p>