First, let's explain what's going on.
Within edit1_Callback
, you're applying setappdata
to hObject
. At this point hObject
refers to edit1
, the editbox, and you've set its application data value H
to 5.
Then you're calling getappdata
within pushbutton1_Callback
. At this point hObject
refers to pushbutton1
, and you're getting its application data value H
, which has never been set, so you get []
.
A previous answer has suggested that you instead use setappdata
and getappdata
on the root object 0. This would work, but it's basically the same as using a global variable, which is BAD.
Instead, I would suggest that you most likely want to just ensure that you're setting and getting the application data on the correct thing. Within edit1_Callback
, try:
setappdata(handles.edit1,'H',C)
and within pushbutton1_Callback
, try:
N=getappdata(handles.edit1, 'H')
I think that should work (it assumes that the editbox is actually called edit1
, which I think is likely given your GUIDE-generated code, but change that if you've called it something else).