timing question

Hello! I am very new with psychtoolbox so I have an important question about timing. In the simple script below i am trying to make the word " FEEDBACK" appear on my screen for a certain amount of time. I've done this based on a demo i found online but I don't know for how long the word appears on screen. How can I make the presentation last for ...le'ts say 4 secs and display the presentation duration on my command line? 

Thank you!




% Clear the workspace and the screen

close all;

clearvars;

sca

Screen('Preference', 'SkipSyncTests', 1);

% Here we call some default settings for setting up Psychtoolbox

PsychDefaultSetup(2);


% Get the screen numbers

screens = Screen('Screens');


% Select the external screen if it is present, else revert to the native

% screen

screenNumber = max(screens);


% Define black, white and grey

black = BlackIndex(screenNumber);

white = WhiteIndex(screenNumber);

grey = white / 2;


% Open an on screen window and color it grey

[window, windowRect] = PsychImaging('OpenWindow', screenNumber, grey);


% Set the blend funciton for the screen

Screen('BlendFunction', window, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');


% Get the size of the on screen window in pixels

% For help see: Screen WindowSize?

[screenXpixels, screenYpixels] = Screen('WindowSize', window);


% Get the centre coordinate of the window in pixels

% For help see: help RectCenter

[xCenter, yCenter] = RectCenter(windowRect);



% Retreive the maximum priority number

topPriorityLevel = MaxPriority(window);  %to window ths line 22


Priority(topPriorityLevel);

vbl = Screen('Flip', window);% to window ths line 22


% Query the frame duration

ifi = Screen('GetFlipInterval', window);

numSecs = 1;

numFrames = round(numSecs / ifi);

waitframes = 1;

for frame = 1:numFrames


    % Draw text in the upper portion of the screen with the default font in red

    Screen('TextSize', window, 70);

    DrawFormattedText(window, 'FEEDBACK', 'center',...

        screenYpixels * 0.25, [1 0 0]);


    % Flip to the screen

    vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);  %deixnei 'feedback' gia periorismeno xroniko diasthma

    


end

Priority(0);


sca;