MATLAB Answers

How to avoid errors when modifing data using guidata and get?

1 view (last 30 days)
How can I modify and then store a value in editable box using guidata. In the future I will be need to retrieve that value in other GUI and maybe modify it also. I get the next error when executing for the second time a callback.
Error using handle.handle/get
Invalid or deleted object.
Error in Initial_parameters>button_1_callback (line 63)
Error while evaluating UIControl Callback
The main function's code and the callback's function are the following:
function i_p = Initial_parameters(hObject,eventdata)
%Initial_parameters is a function in which you can store
%the velocity and density of the air
%Creation of the figure
fig = figure('units','pixels',...
'position',[50 500 400 100],...
'name','Расчет АХ самолетов - Исходные данные',...
i_p = guihandles(fig);
i_p.text1 = uicontrol('style','text',...
'position',[0.05 0.6833 0.255 0.2666],... %'min',0,'max',2,... % This is the key to multiline edits.
'string','Скорость полета');
i_p.Vpol = uicontrol('style','edit',...
'position',[0.355 0.6833 0.595 0.2666],... %'min',0,'max',2,... % This is the key to multiline edits.
'tag','flight velocity');
i_p.text2 = uicontrol('style','text',...
'position',[0.05 0.3666 0.255 0.2666],... %'min',0,'max',2,... % This is the key to multiline edits.
'string','Плотность воздуха');
i_p.plotn = uicontrol('style','edit',...
'position',[0.355 0.3666 0.595 0.2666],... %'min',0,'max',2,... % This is the key to multiline edits.
'tag','air density');
i_p.pushbutton_1 = uicontrol('style','push',...
'position',[0.05 0.05 0.425 0.2666],...
i_p.pushbutton_2 = uicontrol('style','push',...
'position',[0.525 0.05 0.425 0.2666],...
'callback','close all;Main_menu');
%display([i_p.Vpol i_p.plotn]);
uicontrol(i_p.Vpol) % Give the editbox control.
%Save the values
function button_1_callback(hObject,eventdata)
%button_1_callback is a function that change the value
%stored in Vpol and plotn
% Error using handle.handle/get
% Invalid or deleted object.
% Error in Initial_parameters>button_1_callback (line 58)
% i_p.Vpol=str2double(get(i_p.Vpol,'string'));
% Error while evaluating UIControl Callback
display([i_p.Vpol i_p.plotn]);


Sign in to comment.

Accepted Answer

Geoff Hayes
Geoff Hayes on 23 Mar 2018
Oscar - look closely at this line in your pushbutton1 callback
You are getting the string value from the edit text box whose handle is i_p.Vpol AND then replacing this handle with the numeric equivalent of this string
This means that on a subsequent call to the pushbutton1 callback, you will be using an invalid handle when trying to access the edit text control. You will want to save this result to some other field within the structure
i_p.Vpol_value = str2double(...
You may also want to prefix all of your handles with h to make it clear that it is a handle and not something that should be overwritten
i_p.hVpol = uicontrol('...


Show 1 older comment
Geoff Hayes
Geoff Hayes on 26 Mar 2018
Oscar - which line of code is generating this error? If you want to communicate data between GUIs, then please see for one example.
Oscar Espinosa
Oscar Espinosa on 27 Mar 2018

The error is the next:

Undefined function or variable 'hObject'.
Error in Z_INP (line 5)
Error in run (line 64)
evalin('caller', [script ';']);
Error in Results_AERO (line 6)
run ('\\mscs-fs\data\310_user_data\3 факультет\3214\Espinosa Barcenas O.U\m0_17_11_17 -
Error while evaluating uicontrol Callback

Basically first I need to open the Input_parameters (Исходные данные button) UI from this menu

,then I save the data, close the UI and open the next UI (Расчет АХ)but a function need to be executed with the saved data. Those are codes of the menu and the the function where the values are needed:

function Main_menu()
%Main_menu is our menu in which you can select, first store the values in
%the first row and then start with the calculation for the aerodynamic
%coeficients and aproximated empty weight of the aircraft
%Creation of the figure
fig = figure('units','pixels',...
                  'position',[0.0725 0.0725 400 100],...
                  'name','Расчет АХ самолетов - Меню',...
menu = guihandles(fig);
%Figure in the center
scrsz = get(0, 'ScreenSize');
xr=scrsz(3) - pos_act(3);
yr=scrsz(4) - pos_act(4);
set(gcf,'Position',[xp yp pos_act(3) pos_act(4)]);
%Initial parameters
menu.pb_i_p=uicontrol('Style','pushbutton', ...
                'Units','normalized', ...
                'Position',[0.05 0.6833 0.255 0.2666], ...
                'String','Исходные данные',...
%Geometrical characteristics 
menu.pb_g_c=uicontrol('Style','pushbutton', ...
                'Units','normalized', ...
                'Position',[0.355 0.6833 0.595 0.2666], ...
                'String','Геометрические характеристики',...
%Aerodynamic calculation without deformation
menu.pb_AERO=uicontrol('Style','pushbutton', ...
                'Units','normalized', ...
                'Position',[0.05 0.3666 0.255 0.2666], ...
                'String','Расчет АХ',...
%Aerodynamic calculation with deformation
menu.pb_AERO_for_def=uicontrol('Style','pushbutton', ...
                'Units','normalized', ...
                'Position',[0.355 0.3666 0.595 0.2666], ...
                'String','Расчет АХ с учетом деформации',...
                'Callback','clear all; close all;clc;');
%Empty weight calculation without deformation
menu.pb_m0=uicontrol('Style','pushbutton', ...
                'Units','normalized', ...
                'Position',[0.05 0.05 0.255 0.2666], ...
                'String','Расчет m0',...
                'Callback','clear all; close all;clc; Interface;');
%Empty weight calculation with deformation
menu.pb_5=uicontrol('Style','pushbutton', ...
                'Units','normalized', ...
                'Position',[0.355 0.05 0.595 0.2666], ...
                'String','Расчет m0 с учетом деформации',...
                'Callback','clear all; close all;clc;');

I just add the part of the code because is quite extense.

function [sys,Inp,geom_aircraft]=Z_INP()
sys.RASP='\\mscs-fs\data\310_user_data\3 факультет\3214\Espinosa Barcenas O.U\m0_17_11_17 - GUI';
sys.RASP1='\\mscs-fs\data\310_user_data\3 факультет\3214\Espinosa Barcenas O.U\m0_17_11_17 - GUI\ansys';
sys.Ansys='"C:\Program Files\ANSYS Inc\v182\ANSYS\bin\winx64\ansys182.exe"';
%Inp.m0=str2double(get(i_p.m0,'String')); %взлетная масса первого приближения (в килограммах)
%Inp.P0=str2double(get(i_p.p0,'String'));%удельная нагрузка на крыло(кг/мм^2)
Inp.S=Inp.m0/Inp.P0;%площадь (в мм^2)
%Inp.lz=str2double(get(handles.lz,'String')); %удлинение
%Inp.str=str2double(get(handles.str,'String')); %стреловидность,'String')); %сужение
Inp.str_25 = 27.3; %угол стреловидности на 0,25
Inp.PROF_type = 0; %0 - классический профиль, 1 - суперкритический профиль
Inp.S_WF_ = 0.15; %относительная подфюзеляжная площадь крыла
Inp.Lk=0.5*sqrt(Inp.S*Inp.lz);%0.5*sqrt(S*lz); %размах консоли крыла (в мм)12252.5;
Inp.b0=(Inp.S*2**Inp.Lk*(;%(S*2*nu)/(2*Lk*(1+nu)); %корневая хорда (в мм)
Inp.bk=Inp.b0/;%b0/nu; %концевая хорда (в мм)
%Inp.c_=str2double(get(handles.c_,'String')); %относительная толщина профиля в корневой хорде 
%Inp.c_k_koef=str2double(get(handles.c_k_koef,'String'));%отношение c_k/c_ 
Inp.ck_=Inp.c_*Inp.c_k_koef;%0.09;%относительная толщина профиля в концевой хорде, 
Inp.Lpol=4500; %дальность полета (в км)
%Полетные параметры
%Inp.alpha=str2double(get(handles.alpha,'String'));    %%угол атаки в градусах   
Inp.g=9.8; %ускорение свободного падения
Inp.Cp=0.6; %удельный расход топлива
Inp.plotn=i_p_value.plotn; %плотность воздуха
Inp.visc=1.98*10^-5; %Вязкость
Oscar Espinosa
Oscar Espinosa on 27 Mar 2018
Thank you for the help Geoff,the example that you send me really helped, now I can retrieve data from the others UIs.

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!