How do i put content in a text box into a list in GUI?

I am trying to put content inside a text box into a list. So i make a list, namelist = cell(2,6),
and then i did
namelist(1,2) = get(hObject, 'String')
for every text box i have (number inside different)
but when i run my GUI it keeps on giving me weird numbers, i enter 1 number, it gives me like 50s or 60s or even 100s for every number in the list. If i try to input something that is 2 letters, for example "12", it gives me error saying dimesion mismatch. If anyone knows what i am doing wrong please help! Thanks

Answers (5)

You need to use namelist{1,2} = get(hObject, 'String')
Notice the curly bracket {}, instead of parentheses ()

5 Comments

didnt work still gives me error
I sense you need some basics about GUI programming.
Are you trying to put the content of an "Edit" to an "Listbox"? The "Edit" and "Listbox" here refer to the "style" when you use uicontrol('style','Edit') or uicontrol('style','Listbox'). You can also do that through GUIDE, which is the element you drag and drop from the GUI palette.
i am trying to put the content of a textbox in the GUI into a list (not a listbox), like mylist(1), will give me the contents in the first box. thanks
Okay, first let's try to get rid of the error. You have many textbox. Every textbox will have a callback function. In the callback function, you run namelist=cell(2,6);namelist{i,j}=get(hObject,'String'); i and j vary depending on which textbox. It should not have error has long as i is 1 or 2. j is any number from 1 to 6. Remember though, you won't be able to combine all the text into namelist because you are not saving and passing data yet. Every time you edit the textbox, it's going to set one cell in namelist and then namelist is lost. You can only see the value change when you debug. But anyway, what is your error message?
i am getting
"??? Subscripted assignment dimension mismatch."
I have 12 text boxes, and trying to save all 12 strings into one list. but right now, no matter what i put in, its giving me a bunch of 49s, i dont even know where the 49s come from

Sign in to comment.

it didnt work....still gives me some weird error
Just to clarify--you have the textbox in a GUI, and you want to put all numbers from the text box into a list? If it's a list of numbers you want, you might need to use the str2num or str2double function so that you don't get a dimension mismatch since what you're getting from the GUI is a string.
At least, that's what I think. If that doesn't do anything, what exactly is the error that you get?

3 Comments

textbox(s) (i am using like 12 textboxes) in GUI yes, and then i try to put the stuff from those boxes (12 strings) into a 2X6 list. If i dont put in just a single digit number, i get a
"??? Subscripted assignment dimension mismatch."
and even if i dont put in any numbers or anything at all, i get 6X2 list of 49s!
Could you assign get(hObject, 'String') to a variable, then find out what class that variable is for me? Just say, a = get(hObject, 'String') and type class a in the command editor.
Thanks!

Sign in to comment.

it says char

3 Comments

OK, good. If your numlist is a cell, and you assign numlist{x,y} (with curly braces) to anything, there shouldn't be an assignment mismatch. I saw above that you get an error when you try to assign it this way--what's that error?
??? Cell contents assignment to a non-cell array object.
namelist{2,5} = get(hObject, 'String')
so its like that right now

Sign in to comment.

ah i fixed it, turns out i forgot to put global at the palce where i made the array, gah such a stupid mistake, sorry about wasting all your time

1 Comment

No worries--it always seems to end up being something that simple.

Sign in to comment.

Categories

Tags

Asked:

on 19 Sep 2011

Community Treasure Hunt

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

Start Hunting!