Magnification of a colored image through two color space: RGB & YCbCr
I have checked your code and it worked fine in my matab 6.0 implementation with the following lines of of modification: 

A=double(imread('Sun.jpg'));  % convert uint8 data to double
...                           % further operations here
A1(A1(:)&lt;0.0) = 0.0;          % check and correct out of range values
A1(A1(:)&gt;255.0) = 255.0;      % check and correct out of range values
imwrite(A1/255.0,'Sun1.jpg'); % while writing the data of class double use [0,1] data range 


According to this, as I said you must deal with numerical issues such as an out of range value.