I've to remove for loops from a code to speed it up.
the code is:
function [S p] = similarityMatrix(data,candidates)[row,col] = size(data);S = zeros(row,col,row*col);if nargin == 1 candidates = 1:numel(data);endfor z = 1 : numel(candidates) c = candidates(z); for i = 1 : row for j = 1 : col if c == sub2ind(size(data),i,j); S(i,j,z) = NaN; else S(i,j,z) = -dist(data(c),data(i,j)); end end endend%aggiungo le preferenze
p = nanmedian(S(:));S(isnan(S)) = p;
is there a way to improve it?
Best Answer