2011-12-11 3 views
-1

Comment vectoriser ce type de code dans matlab?Vectorisation de boucles imbriquées dans matlab

for i = 1:N 
for k = 1:64 
    if (pixels(i,k)==1) 
    p(character(i),k)= p(character(i),k)+1; 
    end 
end  
end 
+1

double possible de [Vectorisation boucle en Matlab] (http://stackoverflow.com/questions/8462330/vectorizing-for-loop-in- matlab) –

Répondre

1

Les points suivants doivent être équivalentes:

[i,j] = find(pixels(i,k) == 1); 
if ~isempty(i) 
    ind = sub2ind(size(p), character(i), j); 
    % or, equivalently: 
    % ind = character(i) + (j-1) * size(p,1); 
    p(ind) = p(ind) + 1; 
end 
Questions connexes