Think i have found a solution to the problem. It is slow but working fine.
I went with following reducing technique.
- Removing row ii where the slope of e(ii-1) to e(ii) = e(ii) to e(ii+1)
- Deleting every 2nd row if there are more than 40 rows.
- Loop where it for every loop find the point with biggest difference in x-value between the original curve and the reduced data curve. Then this point is added to my reduced data.
The code i used to find the difference is:
e_temp = [z*-1 zeros(h/dz+1,1)] ;
j = 1 ; % counter
for i = 1:length(e)-1
if abs((e(i,1)-e(i+1,1))-dz) < dz*0.1 % if the two points is right next to each other
e_temp(j,2) = e(i,2) ;
j = j + 1 ;
else % if there is missing some points in between e(i) and e(i+1)
num = round((e(i,1)-e(i+1,1))/dz) ; % Number of "steps" missing
for ii = 1:num
slope = (e(i+1,2)-e(i,2))/(num) ;% Slope
e_temp(j,2) = e(i,2)+slope*(ii-1) ;
j = j+1 ;
end
end
end
e_temp(j,2) = e(end,2) ; % adding last point
Where: e_temp is a matrix with the size of the matrix to create the original curve, but with reduced point inside. The y-values where no reduced point is available is the point calculated by linear interpolation between point e(i) and e(i+1).