I have a cell array (data) containing 3 matrices, each with 18 columns and 108021, 108022 and 108021 rows respectively. I need to calculate the Euclidean distance between columns 13, 14 and 15, 16 for each matrix and I am using the following code:
for m = 1:length(data)
for i = 1:length(data{m})
distance(i) = norm(data{m}(i,13:14)-data{m}(i,15:16));
end
end
It works except for the last matrix (when m=3) to which it adds an extra element. So that now distance is a cell array with 3 vectors of sizes 108021, 108022 and 108022...
Anyone knows whats wrong here?
Thanks!
Auesro
distance{m}(i) = norm(.... Now the vectordistanceis overwritten with each outer loop iteration, and since the middle loop makes the vector 108022 elements, it will keep this last element untouched in the last iteration, i.e. whenm=3. - rinkert