Chethan
Chethan

Reputation: 213

tic toc command in MATLAB GUI

I'm using tic toc commands to know about the computation speed, however if i use this command it gives output in command window.

I need to minimize all GUI'S to check time taken by my code.

function Texture_Callback(hObject, eventdata, handles)
% hObject    handle to Texture (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
tic
disp('Texture part starting...');
        % Texture go...
        queryEnergies = obtainEnergies(handles.queryx, 5);       
        % Open colourResults txt file... for reading...
        fid = fopen('database.txt');
        fresultValues = [];      % Results matrix...
        fresultNames = {};
        i = 1;                  % Indices...
        j = 1;
        while 1
             imagename = fgetl(fid);
            if ~ischar(imagename), break, end       % Meaning: End of File...    
                [X, RGBmap] = imread(imagename);
                imageEnergies = obtainEnergies(X, 5);
                E = euclideanDistance(queryEnergies, imageEnergies);
                fresultValues(i) = E;
                fresultNames(j) = {imagename};
                i = i + 1;
                j = j + 1;
        end
        fclose(fid);
        disp('Texture results obtained...');
        % Sorting final results...
        [sortedValues, index] = sort(fresultValues);     % Sorted results....
        fid = fopen('textureResults.txt', 'w+');         % Create a file
        for i = 1:5        % Store top 5 matches...
             imagename = char(fresultNames(index(i)));
            fprintf(fid, '%s\r', imagename);
            disp(imagename);
            disp(sortedValues(i));
            disp('  ');
        end
        fclose(fid);
        toc

Above code runs when i press texture search button. How can i display time on GUI window? So, that user can easily estimate computation speed without minimizing any windows.

Upvotes: 0

Views: 1741

Answers (1)

David K
David K

Reputation: 1346

First, put a semicolon after tic and toc to prevent it from printing. You can set the value from toc to a variable:

time = toc;

And display it wherever you want.

Upvotes: 2

Related Questions