Is there a way to ask the user the hours?

3 ビュー (過去 30 日間)
André Magrinho
André Magrinho 2016 年 1 月 12 日
回答済み: Image Analyst 2016 年 1 月 12 日
I'm making a interactive clock , and one of the features that the clock have is a "reminder". I'd like to know if there is a way to ask the user at what time would he like to receive the pop-up message and if i could put it in a while . I'm imagining something like give a variable to the time inputed to the user, and then use a while cycle, so when the variable turns false ( a.k.a the time that the user inputed is the time "now" ) the reminder would pop up. Can someone help?

採用された回答

Image Analyst
Image Analyst 2016 年 1 月 12 日
Here's a robust snippet using inputdlg() that you can adapt.
% Ask user for one integer number.
defaultValue = 45;
titleBar = 'Enter an integer value';
userPrompt = 'Enter the integer';
caUserInput = inputdlg(userPrompt, titleBar, 1, {num2str(defaultValue)});
if isempty(caUserInput),return,end; % Bail out if they clicked Cancel.
% Round to nearest integer in case they entered a floating point number.
integerValue = round(str2double(cell2mat(caUserInput)));
% Check for a valid integer.
if isnan(integerValue)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
integerValue = defaultValue;
message = sprintf('I said it had to be an integer.\nI will use %d and continue.', integerValue);
uiwait(warndlg(message));
end

その他の回答 (1 件)

jgg
jgg 2016 年 1 月 12 日
編集済み: jgg 2016 年 1 月 12 日
You'd still need some kind of a tic-cycle to poll the current time, which is probably the guts of your clock function. I think the thing you want is etime if you're using strings, but otherwise:
Basically, when the reminder is set call:
%get input time
t = input('Remind in how many seconds: ')
reminder_time = now + t;
timer_on = true;
Then just add a check on clock tic:
if now >= reminder_time && timer_on
popup_reminder() %your function
timer_on = false;
end
Probably better than using a while loop.

カテゴリ

Help Center および File ExchangeClocks and Timers についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by