MATLAB图形用户界面中的tic-toc命令
我使用tic-toc命令来了解计算速度,但是如果我使用这个命令,它会在MATLAB图形用户界面中的tic-toc命令,matlab,matlab-figure,matlab-guide,Matlab,Matlab Figure,Matlab Guide,我使用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 stru
命令窗口中给出输出
我需要最小化所有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
当我按下纹理搜索按钮时,上面的代码运行。如何在GUI窗口上显示时间?因此,用户可以在不最小化任何窗口的情况下轻松估计计算速度。首先,在tic
和toc
后面加一个分号,以防止打印。您可以将toc
中的值设置为变量:
time = toc;
并将其显示在您想要的任何位置。同时检查ticID=tic
和elapsedTime=toc(ticID)
语法,允许在我要显示的GUI中执行多次检查。但是,使用编辑文本
如何显示?@chetz-我不确定。您给出的代码是较大代码集的一部分,因此很难知道如何与GUI交互。您可能需要将时间值返回到更高级别的代码。disp
是否显示在命令或GUI中?disp(imagename);disp(分类价值(i))代码>在命令窗口中显示结果。但是,我在t=toc
命令之后使用了disp(get(handles.time,'string'))
。其中,time
是我的编辑文本
功能/标签名称。但无法在文本框中显示时间。@chetz:Tryset(handles.time,'string',num2str(t))代码>