If you are not concerned with the length of the envelope signal you can use the "findpeaks" function.
[pks, locs] = findpeaks(i); % Where pks is a vector with amplitude of peaks and locs is a vector of peak indeces
envelope = interp(pks,floor(length(i)/length(pks)); % Interpolate peaks to vector close in size to i
Please note that the interpolation function only works with integer multiples of length so this will not produce an envelope vector equal in size to the original signal. You can refer to the following MATLAB answers post for more information on this:
Also, I have included a link to the findpeaks function documentation for your convenience: