2013-05-15 40 views
0

我使用tic toc命令來了解計算速度,但是如果我使用這個命令,它會在command window中給出輸出。在MATLAB GUI中的tic toc命令

我需要最小化所有GUI來檢查我的代碼所花費的時間。

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 

上面的代碼運行時,我按texture search按鈕。我如何在GUI窗口上顯示時間?因此,該用戶可以輕鬆估計計算速度,而無需最小化任何窗口。

回答

2

首先,在tictoc之後加上分號以防止打印。您可以從toc值設置爲一個變量:

time = toc; 

而且不管你想要顯示它。

+1

同時檢查允許執行多次檢查的'ticID = tic;'和'elapsedTime = toc(ticID)'語法 – anandr

+0

在我想要顯示的GUI中。但是,使用'編輯文本'我怎麼顯示? – Chethan

+0

@chetz - 我不確定。您提供的代碼是更大代碼集的一部分,因此很難知道如何與GUI進行交互。您可能需要將您的時間值返回到更高級別的代碼。 'disp'是否顯示在命令或GUI中? –