フィルターのクリア

IF statement inside a push button

1 回表示 (過去 30 日間)
ericson
ericson 2014 年 2 月 5 日
回答済み: Image Analyst 2014 年 2 月 6 日
Hi! I have a gui which stores a numerical value in a variable from the edit text when I click the apply button (push button). I want to add an if statement stating that when the numerical value is the same as the current time, also stored in another variable, the background color of a push button will change.
There is no error in the code when I run it, but the if statement inside the push button is not working. Here is some of the code:
apply_Callback(hObject, eventdata, handles) mon1= get(handles.m1,'string'); %get from the edit text t=clock;
t1=num2str(fix(t(5)));
if mon1==t1
set(handles.b101,'BackgroundColor','red');
end

採用された回答

Amit
Amit 2014 年 2 月 5 日
Assuming rest of the code is right
mon1= str2num(get(handles.m1,'string'));
The first thing I'll think is that you're getting a string in mon1 and comparing that to a integer would be false in all cases.
  1 件のコメント
ericson
ericson 2014 年 2 月 6 日
but t1 is num2str, so why is it that mon1 is str2num? shouldn't it be the same ? i.e. t1 is num2str and min1 is num2str

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2014 年 2 月 6 日
Try this:
% Read user's input in the edit field.
% editString = get(handles.edit1, 'String');
% Give an example of what would be a match if they typed it in correctly.
editString = '05-Feb-2014 18:12:11' % For testing/debugging.
currentTimeString = datestr(now)
if strcmp(editString, currentTimeString)
uiwait(msgbox('They Match!!!!'));
else
fprintf('%s does not match %s\n', editString, currentTimeString);
end
You can modify the time strings if you don't want to check for matching seconds but only minutes or days or whatever.

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by