我们如何在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
答案 0 :(得分:1)
以下内容应相同:
[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