You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: rgb2hsv.m
    path of file: ./repos/bspm/thirdparty/spm12/external/fieldtrip/external/images
    
    the code of the file until where you have to start completion: function h = rgb2hsv(m)

% RGB2HSV converts red-green-blue colors to hue-saturation-value.
%
% this code is based on the comments in
% http://stackoverflow.com/questions/3018313/algorithm-to-convert-rgb-to-hsv-and-hsv-to-rgb-in-range-0-255-for-both

if isvector(m) && length(m)==3

    
function h = rgb2hsv(m)

% RGB2HSV converts red-green-blue colors to hue-saturation-value.
%
% this code is based on the comments in
% http://stackoverflow.com/questions/3018313/algorithm-to-convert-rgb-to-hsv-and-hsv-to-rgb-in-range-0-255-for-both

if isvector(m) && length(m)==3
  r = m(1);
  g = m(2);
  b = m(3);
elseif ismatrix(m) && size(m,2)==3
  r = m(:,1);
  g = m(:,2);
  b = m(:,3);
elseif ndims(m)==3
  r = m(:,:,1);
  g = m(:,:,2);
  b = m(:,:,3);
end