You have the bin values. You know which bins you want. Why are you zeroing the histogram counts instead of changing the image?
% the image
im = imread('rainbow.png');
hsv_im = rgb2hsv(im);
h = hsv_im(:,:,1);
% generate the mask
nbins = 360;
[~, bincenters] = hist(h(:),nbins);
maskrange = bincenters([20 30]) + [-0.5 0.5]/nbins;
mask = (h >= maskrange(1)) & (h <= maskrange(2));
% make the masked region red
h(mask) = 0;
% reassemble the image
hsv_im(:,:,1) = h;
outpict = hsv2rgb(hsv_im);
% it's red
imshow(outpict)
Of course I have to question whether the goal was to actually set orange pixels to red, or whether it was to reshape the entire histogram such that there are no orange pixels. I guess we'll never know.
EDIT:
Just because I felt like it:
% the image
im = imread('rainbow.png');
hsv_im = rgb2hsv(im);
h = hsv_im(:,:,1);
% crudely reshape the histogram
nbins = 360;
[bincounts, bincenters] = imhist(h,nbins);
bincounts(20:30) = 0;
% make the masked region red
hnew = histeq(h,bincounts);
% reassemble the image
hsv_im(:,:,1) = hnew;
outpict = hsv2rgb(hsv_im);
% it's still red
imshow(outpict)
% show that the histogram has a hole in it
subplot(2,1,1)
imhist(h)
subplot(2,1,2)
imhist(hnew)
% inspect that part
countsnew = imhist(hnew,nbins); % need to call imhist() twice
countsnew(20:30) % yes they're zero
% show how the hues were shifted
comp = [im(1:250,:,:); im2uint8(outpict(251:end,:,:))];
imshow(comp)