I'm getting a Error using get, Unrecognized property String for class Root. in my program, all I what is to hit the push button and have no problem.

49 views (last 30 days)
Error while evaluating UIControl Callback.
>> BSA
Error using get
Unrecognized property String for class Root.
Error in BSA>height_Callback (line 113)
handles.height= str2double(get(handles.height, 'String'));
--------------------------------------------------------------------------
function kilograms_Callback(hObject, eventdata, handles)
% hObject handle to kilograms (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of kilograms as text
% str2double(get(hObject,'String')) returns contents of kilograms as a double
handles.kilograms= str2double(get(handles.kilograms, 'String'));
guidata(hObject,handles)
-----------------------------------------------------------------------------------
function height_Callback(hObject, eventdata, handles)
% hObject handle to height (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of height as text
% str2double(get(hObject,'String')) returns contents of height as a double
handles.height= str2double(get(handles.height, 'String')); %line 115
guidata(hObject,handles)
-------------------------------------------------------------------------------------------------
function Enterbotton_Callback(hObject, eventdata, handles)
% hObject handle to Enterbotton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.kilograms= str2double(get(handles.kilograms,'string'));
handles.height= str2double(get(handles.height,'string'));
handles.BSA= 0.007184*(handles.kilograms)^0.425*(handles.height)^0.75;
set(handles.pantalla,'string',handles.BSA);
guidata(hObject,handles)

Accepted Answer

Voss
Voss on 13 Feb 2022
On this line:
handles.height= str2double(get(handles.height,'string'));
You are getting the 'String' property of the uicontrol handles.height, converting it to a number, and then using that number to overwrite the field 'height' in the handles structure. Then in the future, when you refer to handles.height you are referring to this number instead of the uicontrol that handles.height originally was.
And if that String happened to be '0', then, after that line executes, handles.height is the number 0, which also happens to be the handle to the root graphics object groot(), which does not have a 'String' property, so you get the error you saw the next time you try to exeucte that same line.
The solution is not to overwrite your uicontrols in the handles structure. If you want to store the value of a uicontrol's String as a number, you should use a name different from the name of the uicontrol. For instance:
handles.height_value = str2double(get(handles.height,'string'));
handles.kilograms_value = str2double(get(handles.kilograms,'string'));
These changes would need to be made wherever the old logic appeared, which is two for each of those that I can see in the code you posted. Then restart your GUI to restore the original handles structure and try it again.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!