function [quantized, maxindexnew, minindexnew] = QuantizeCoefs3(coefs, intstepsize, maxindexmat, minindexmat)

quantized = round(coefs/intstepsize);

maxindexnew = maxindexmat;
minindexnew = minindexmat;


changevalues = find(quantized>maxindexmat);
maxindexnew(changevalues) = quantized(changevalues); 

changevalues = find(quantized<minindexmat);
minindexnew(changevalues) = quantized(changevalues); 