MATLAB: How to calculate the average with “for loop”

csvfor loopmeanwhile loop

Hello. I'm beginner at Matlab.
I want to calculate the average of DTW distances using rows.
For example, I have two datasets, data11(19200 x 25), data22(19200 x 25).
After computing the DTW distance between two rows, I wanna get the average value of all dtw distances.
Please let me know how to get the average value using "For loop" code.
clear all
data11 = csvread('person01_boxing_d1_uncomp.csv');
data22 = csvread('person01_handclapping_d1_uncomp.csv');
x = data11(1,:); % 1 ~ 19200

y = data22(19199,:); % 1 ~ 19200
dtw(x,y);
% I get one dtw distance.
% I want to compute the average value of all kk, kk1, kk3, .....
x = data11(1,:);
y = data22(1,:);
kk = dtw(x,y);
x = data11(1,:);
y = data22(2,:);
kk1 = dtw(x,y);
x = data11(1,:);
y = data22(19199,:);
kk3 = dtw(x,y);
average = mean(kk, kk1, kk3) % ??

Best Answer

How to calculate the average with "for loop"
data11 = csvread('person01_boxing_d1_uncomp.csv');
data22 = csvread('person01_handclapping_d1_uncomp.csv');
x = data11(1,:); % 1 ~ 19200
kk=zeros(1,size(data22,1)-1);
for i=1:length(kk)
y = data22(i,:);
kk(i)= dtw(x,y);
end
mean(kk)