MATLAB GUI中的tic toc命令

时间:2013-05-15 17:47:38

标签: matlab matlab-figure matlab-guide

我正在使用tic toc命令来了解计算速度,但是如果我使用此命令,它会在command window中提供输出。

我需要最小化所有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窗口上显示时间?因此,该用户可以轻松估计计算速度,而不会最小化任何窗口。

1 个答案:

答案 0 :(得分:2)

首先,在tictoc之后加一个分号以防止它打印。您可以将值从toc设置为变量:

time = toc;

并在任何地方显示。