Explanation for the quantization matlab function
sigp = (sig_in - sig_nmax)/Delta + 1/2;   % convert into 1/2 to L+1/2 range
qindex = round(sigp);                     % round to 1,2,3..... L levels 
qindex = min(qindex,L);                   % Eliminate L+1 as rare possibility
q_out = q_level(qindex);                  % use index vector to generate output
clear
end


sigp is a mid-tread uniform quantizer which is defined using the quantization step size Delta whose details you can find here: https://en.wikipedia.org/wiki/Quantization_(signal_processing)#Mid-riser_and_mid-tread_uniform_quantizers

sigp uses sig_in - sig_nmax instead of sig_in so that the signal can lie between 0 and 2 instead of -1 and 1 since indexing in MATLAB is always greater than 0

1/2 is added to round the first index to 1.

qindex = min(qindex,L);


The highest level can be L so if qindex goes over L, it is truncated to L

q_out = q_level(qindex);


q_out gives the quantization level corresponding to the qindex.