MATLAB: Help for vectorization?

for loopsvectroization

incI=zeros(length(featInd),length(tempInd));
for f = 1:length(featInd)
incI(f,:) = tempInd + featInd(f);
end
for k=1:length(featInd)
h([incI(k,:)]') = h([incI(k,:)]')+ 1;
end

Best Answer

Here is an example you can try
featInd = 1:24636;
tempInd = 1:12332;
incI = bsxfun(@plus,featInd(:),tempInd);
As to the second loop, I could be wrong but that looks just like a histogram for me, so you can probably do something like
[incU,~,incInd] = unique(incI(:),'stable');
h = zeros(14593760,1);
h(incU) = h(incU)+accumarray(incInd,ones(numel(incInd),1));
Related Question