MATLAB: How to change width and height of image

reduce size of image

Hey, I'm trying to reduce the size of the height and width of an image only if the image width or height is over 400 pixels. Anybody know how I can do that? Here's the code:
im = imread('harry.jpg');
info = imfinfo('harry.jpg');
hoyde = info.Height;
bredde = info.Width;
if hoyde > 400 bredde > 400
nyhoyde = hoyde/2;
nybredde = bredde/2;
[nyhoyde,nybredde,kanaler] = size(im);
end

Best Answer

Not sure I understand the language you used, but I'd do it like this:
reductionFactor = 0.5; % whatever...
[rows columns numberOfColorChannels] = size(im);
if rows>400 || columns > 400
im = imresize(im, reductionFactor);
end