How do i put content in a text box into a list in GUI?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (5개)
Fangjun Jiang
2011년 9월 19일
You need to use namelist{1,2} = get(hObject, 'String')
Notice the curly bracket {}, instead of parentheses ()
댓글 수: 5
Fangjun Jiang
2011년 9월 19일
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?
Tigersnooze
2011년 9월 19일
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
Tigersnooze
2011년 9월 19일
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!
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!