I have a matrix with 4500 vectors of 1800 length, for which I need to compute the DTW (Dynamic Time Warping) distance between every 2 vectors in the matrix.
I have used a nested loop to fill up half of a 4500x4500 matrix (which would look like a triangle):
matr = zeros(4500,4500); %initializing empty matrix to fill dtw distance
for i=1:4500
x = new(i,:); %new is where the data lies
for j = i+1:4500
y = new(j,:);
matr(i,j) = dtw(x,y);
end
end
The problem is that the code runs extremely slow. And as per my calculation it will take 4 days to run on my computer.
I have no clue of how vectorization works. But is there a way my code can be vectorized so that it runs faster? Also isn't there an inbuilt function where I could just plug in all my vectors and get a DTW dist matrix auto generated?