0

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

4

1 回答 1

2

首先,在ticand后面加上一个分号toc以防止打印。您可以将值设置toc为变量:

time = toc;

并将其显示在您想要的任何地方。

于 2013-05-15T18:20:39.660 回答