在MATLAB中矢量化循环

Viv*_*ian 6 performance matlab for-loop vector vectorization

有没有办法在MATLAB中对以下循环进行矢量化?

for j = 1:length(cursor_bin)
    cursor_bin(j) = mean(cursor(bin == j));
end
Run Code Online (Sandbox Code Playgroud)

cursor_bin,cursorbin所有载体.

Lui*_*ndo 5

accumarray 这样做:

cursor_bin = accumarray(bin(:), cursor(:), [], @mean);
Run Code Online (Sandbox Code Playgroud)