tic toc in a GUI

5 ビュー (過去 30 日間)
tony karamp
tony karamp 2013 年 4 月 10 日
コメント済み: Walter Roberson 2015 年 8 月 17 日
hello all,
I have created a GUI, using GUIDE. I have added pushbuttons which perform a task. The start button, plots a graph and plays a wavefile that I have assigned to it. in the start button I have added as well a 'tic'.
on the other side of the GUI is have another button, the save button. The function of that button is to save to a vector the exact time that I push the button. The code that I have used saves only the last instance, while I want to be able to see all of the elements of that vector.
handles.counter.push(handles.count + 1)
handles.sfront(size(handles.counter)) = toc
Is there a way to save all of the instances to the sfront vector?
Thank you in advance!

採用された回答

Jan
Jan 2013 年 4 月 11 日
You want to save the time when the button is pressed. This is neither tic/toc not cputime, but clock or now.
To accumulate the time stampes, you have to store them cummulatively, e.g.:
During the creation of the GUI:
handles.counter.push = [];
In the callback of the button:
handles = guidata(hObject); % Get the newest version
handles.counter.push(end + 1) = now;
% Alternatively the DATEVEC format:
% handles.counter.push(end + 1, :) = clock;
guidata(hObject, handles); % Save the updated struct
And finally in the function for saving, handles.counter.push contains all times the button was pressed.
  3 件のコメント
mzakaria
mzakaria 2015 年 8 月 17 日
How did you initialize sfront? I'm trying to do the same thing but I keep getting the error that the variable is unknown.
Walter Roberson
Walter Roberson 2015 年 8 月 17 日
With that code, even if the variable was undefined beforehand, the code would define it. However, it should be
handles.sfront(length(handles.counter)) = toc;
as size() would return a vector with at least two elements and when used to index in the form shown would result in two elements of handles.sfront being set to the result of toc(). Better yet would probably be just
handles.count = handles.count + 1;
handles.sfront(handles.count) = toc;
guidata(hObject, handles);
and before that you would have initialized with
handles.count = 0;
handles.sfront = [];
guidata(hObject, handles);

サインインしてコメントする。

その他の回答 (1 件)

Babak
Babak 2013 年 4 月 10 日
tic toc gives you the total elapsed amount of time. There is no such meaning of all the instances... you cannot save time instances..
  4 件のコメント
tony karamp
tony karamp 2013 年 4 月 10 日
編集済み: tony karamp 2013 年 4 月 10 日
Could I add an action listener, such as in java, with a counter? the value of the counter indicates the position in the vector. How about then?
Babak
Babak 2013 年 4 月 10 日
I don't know. I suggest you create another question and ask your "new" question from public.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by