我有以下for循環,我想矢量化。但是,在for循環中,我使用了circshift。有沒有辦法使用矢量化來執行for循環,或者至少優化它?它的運行速度非常緩慢,停止和M增加它們的大小。MATLAB:矢量化for循環包含circshift
indx = 0;
M = magic(16);
v = M(:,1);
strt=-5;
stop=+5;
result = zeros(4, length(strt:stop), 4);
for ii=strt:stop
tmp = circshift(M, [0 ii])*v;
tmp = tmp/norm(tmp);
indx = indx+1;
result(:, indx, :) = reshape(tmp(:,1), 4,4);
end
其大概[-5; 5]正確? – Finn
@Finn是的,我改變了它 – BillyJean