try
    screens = Screen('Screens');
    whichscreen = max(screens);
    [w, rect] =Screen('Openwindow', whichscreen, 0);
    mytext = 'MATLAB';
    Screen('TextSize',w, 50);
    Screen('TextFont',w, 'Arial');
    for r = [0:2:255, 254:-2:0]
        DrawFormattedText(w, mytext, 'center', 'center', [r, 0, 0]);
        Screen('Flip', w);
    end
    for g = [0:2:255, 254:-2:0]
        DrawFormattedText(w, mytext, 'center', 'center', [0, g, 0], ...
            [], 1, 0);
        Screen('Flip', w);
    end
    for b = [0:2:255, 254:-2:0]
        DrawFormattedText(w, mytext, 'center', 'center', [0, 0, b], ...
            [], 0, 1);
        Screen('Flip', w);
    end
    Screen('Close', w)
catch
    Screen('Close',w)
    rethrow(lasterror)
end