Cell size changes to 49x50 when used in callback function in guide. Can anyone help me out with that?

I have a cell addStrArr which is initiated as cell(5,3) in a function and the cell elements are updated in the callback function named additem_Callback. But the cell size changes to 49x50 in the callback function. I am unable to comprehend. The callback function is as follows.
function additem_Callback(hObject, eventdata, handles)
global addStrArr;
size(addStrArr) % This gives correct size
a=get(hObject,'Tag');
b=a(2) % Say b=1
c=a(3) % Say c=2
f=get(hObject,'String')
addStrArr{b,c}=f % This results in size of 49x50.
addStrArr
size(addStrArr)
Can anyone help out?

 Accepted Answer

The 'tag' is a string. Then:
a = get(hObject,'Tag');
b = a(2) % Say b=1
replies 1 infact, but this is the character '1'. Using it as index converts it to the ASCII code 49:
double('1')
If you really want to use the tag of the object (then it is limited to 10 values because you have 1 digit only), convert it to a number at first:
a = get(hObject,'Tag');
b = a(2) - '0'; % Or: b = sscanf(a(2), '%d')
c = a(3) - '0';
Better use the UserData of the object or the ApplicationData (see doc guidata) instead of the tag property. Then this strange parsing of the tag string is not required, because you can store the indices numerically directly.

2 Comments

Ankit's "Answer" moved here:
Thanks Jan for the reply!
I accepted this answer as it seems that Ankit is satisfied with it.

Sign in to comment.

More Answers (0)

Categories

Find more on App Building in Help Center and File Exchange

Tags

Asked:

on 5 Mar 2017

Commented:

on 2 Apr 2017

Community Treasure Hunt

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

Start Hunting!