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: ConvertRGBImageToGrayscale.m
    path of file: ./repos/ImageM/ImageM/+imagem/+actions/+image
    
    the code of the file until where you have to start completion: classdef ConvertRGBImageToGrayscale < imagem.actions.CurrentImageAction
% One-line description here, please.
%
%   Class C
    
function run(obj, frame) %#ok<INUSL,INUSD>
        
        % get handle to current doc
        doc = frame.Doc;
        
        % check image type
        if ~isColorImage(doc.Image)
            errordlg('Requires a Color image', 'Image Format Error');
            return;
        end
        
        % convert RGB image to grayscale image with uint8 data
        res = rgb2gray(doc.Image);
        
        % add new image to application, and create new display
        [frame2, doc2] = createImageFrame(frame, res); %#ok<ASGLU>
        
        % add history
        string = sprintf('%s = rgb2gray(%s);\n', ...
            doc2.Tag, doc.Tag);
        addToHistory(frame, string);
    end