0

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.

Chethan
  • 213
  • 3
  • 7
  • 19

1 Answers1

2

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.

David K
  • 1,296
  • 18
  • 39
  • 1
    Also check the `ticID = tic;` and `elapsedTime = toc(ticID)` syntax that allows to do multiple time checks – anandr May 15 '13 at 18:41
  • In GUI i want to display. But, using `edit text` how can i display? – Chethan May 16 '13 at 15:19
  • @chetz - I'm not sure. The code you've given is a part of a larger code set, so it's difficult to know how to interact with your GUI. You may need to return your time value back to the higher level code. Does `disp` show up in the command or GUI? – David K May 16 '13 at 15:42
  • `disp(imagename); disp(sortedValues(i));` shows result in command window. However, I've used `disp(get(handles.time,'string'))` after `t = toc` command. Where, `time` is my `edit text` function/tag name. But not able to display time on text box. – Chethan May 16 '13 at 15:51
  • @chetz: Try `set(handles.time,'string',num2str(t));` – David K May 16 '13 at 16:04
  • Well, that helps in displaying time in edit text box, but with warning/error. . `??? One or more output arguments not assigned during call to "set". ` `Error in ==> Fig5>Texture_Callback at 156 disp(set(handles.time,'string',num2str(t)));` – Chethan May 16 '13 at 16:53
  • @chetz: Why do you still have the `disp`? The form of `set` that you want does not return a value. http://www.mathworks.com/help/matlab/ref/set.html – David K May 16 '13 at 17:10