Text doesn't change in guide while i can see it change in the commande window

1 回表示 (過去 30 日間)
0Luk
0Luk 2021 年 6 月 9 日
コメント済み: 0Luk 2021 年 6 月 9 日
Hello, im receiving data from bluetooth, and i want to show it in a guide text using a timer to show it every x seconds, so i wrote the following program, im not getting any error, and i can see values change in the commande window, but nothing changes in the guide. any idea?
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global tmr
stop(tmr)
set(findobj('Tag','text5'),'String', ' ');
set(findobj('Tag','alT'),'String',' ');
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global tmr
tmr = timer('ExecutionMode', 'FixedRate', ...
'Period', 5 , ...
'TimerFcn', {@timerCallback});
start(tmr);
function timerCallback(hObj, eventdata)
global temp Data Temperatura n a
temp = characteristic(Data, "000F1809-0000-0000-0100-000100001809", "000F1006-0000-0000-0100-000100001809");
temperatura = 13 / 255 *read(temp)+32;
if temperatura < 36.3
a = "Hypotermia";
elseif temperatura > 38.3 && temperatura < 40.3
a = "Pyrexia";
elseif temperatura > 40.3
a = "Hypertermia";
else
a = " ";
end
temperatura= round(temperatura, 1);
t = string(temperatura);
set(findobj('Tag','text5'),'String',t);
set(findobj('Tag','alT'),'String',a);

採用された回答

Jan
Jan 2021 年 6 月 9 日
編集済み: Jan 2021 年 6 月 9 日
It is not the cause of your problems, but global variables are a shot in your knee. Avoid them consequently. Instead of searching for a specific tag, you can provide the handle to the callback.
function pushbutton4_Callback(hObject, eventdata, handles)
stop(handles.tmr);
delete(handls.tmr);
handles.text5.String = ' ';
handles.alT.String = ' ';
guidata(hObject, handles);
function pushbutton5_Callback(hObject, eventdata, handles)
handles.tmr = timer('ExecutionMode', 'FixedRate', ...
'Period', 5 , ...
'TimerFcn', {@timerCallback, handles});
start(tmr);
guidata(hObject, handles);
function timerCallback(hObj, eventdata, handles)
temp = characteristic(Data, "000F1809-0000-0000-0100-000100001809", "000F1006-0000-0000-0100-000100001809");
temperatura = 13 / 255 *read(temp)+32;
if temperatura < 36.3
a = "Hypotermia";
elseif temperatura > 38.3 && temperatura < 40.3
a = "Pyrexia";
elseif temperatura > 40.3
a = "Hypertermia";
else
a = " ";
end
temperatura= round(temperatura, 1);
t = string(temperatura);
handles.text5.String = t;
handles.alT.String = a;
drawnow; % <-- use this to update the figure
I assume, the final drawnow solves your problem already.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by