there is this tutorial on peak analysis in the mathworks docs which discribes(in a sitenote) how to detrend data (by doing what Dan suggested):
load noisyecg.mat
t = 1:length(noisyECG_withTrend);
plot(t,noisyECG_withTrend) %load the data with trend
[p,s,mu] = polyfit((1:numel(noisyECG_withTrend))',noisyECG_withTrend,6);
f_y = polyval(p,(1:numel(noisyECG_withTrend))',[],mu); %fitting a polynom in that data
ECG_data = noisyECG_withTrend - f_y; % Detrend data by subtracting the values of said polynom