The code below gives me error = Subscript indices must either be real positive integers or logicals.
Because the first index using FIND function is i=1, the i-1
gives negative value. How to ignore when i==1 without using the LOOP
function
fid=fopen('data.txt');
A=textscan(fid,'%f%f%f%f');
fclose(fid);
in = cell2mat(A);
i = find(in(1:end,2)>20 & in(1:end,2) <50);
out=in;
s(i)=sqrt((out(i,3)-out(i-1,3))*(out(i,3)-out(i-1,3))+(out(i,4)-out(i-1,4))*(out(i,4)-out(i-1,4)));
fid = fopen('newData.txt','wt');
format short g;
fprintf(fid,'%g\t%g\t%g\t%g\n',out',s'); %'# Write the data to the file
fclose(fid);