how come edit box joins text together even when max - min >1
1 view (last 30 days)
Show older comments
Hi, i have a edit box in a gui where i want it to collect all the numbers in it, i changed the value of max to 24 when min remains 0. I'm using this code for now
userdefinedremove = str2double(get(hObject,'String'));
display(userdefinedremove)
the display is to check what value will i get, and i found that when i type 1 (press enter), type 2 (press enter) in the edit box it become 12, i want it to be 1 and 2 separable values.
Is there some thing i did wrongly?
1 Comment
Adam
on 18 Mar 2015
As an aside to my answer below, you can set 'max' to anything greater than 'min' and you will get exactly the same multi-line behaviour. So while setting it to 24 is perfectly valid, don't expect any different behaviour than setting it to 2 or 1. e.g. it will not constrain that you can only have 24 lines.
Strangely the help page on uicontrol properties seems to claim 'edit'components do not use the 'max' property which seems to directly contradict the uicontrol help page which describes the behaviour you are using correctly.
Answers (1)
Adam
on 18 Mar 2015
Edited: Adam
on 18 Mar 2015
This should work:
str = get(hObject,'String');
[nLines, nCols] = size( str );
result = str2double( mat2cell( str, ones(1,nLines), nCols ) )
display( result )
The problem is that str2double will concatenate your multiline string into a single string and convert it to double. You need to convert each row to double not the whole string as one.
There may be other ways of doing this, but the method above is the simplest I found after a quick play around on command line.
See Also
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!