Saving multiple variables with names 'n1', 'n2', etc may be a bad practice, I would recommend using a vector 'n' with indices 1-12 instead.
You may find vector operations much cleaner for your purpose, for example -
You may replace the top part of the code with
n = 2.^[1:12];
% instead of for loop :-
H_vec = (x1-x0)./n;
Once you pick up the habit of vectorizing operations wherever possible, you may rework the code suitably.
You can checkout these links to pick up vectorization:
2) Sections 5,6,12 in Matlab OnRamp online course may be useful
https://www.mathworks.com/help/matlab/matlab_prog/vectorization.html#:~:text=MATLAB%C2%AE%20is%20optimized%20for,vector%20operations%20is%20called%20vectorization.