get command return types
2 次查看(过去 30 天)
显示 更早的评论
when I use the get command to return the contents of a textbox, using get(jObject, 'String')
i get something like 'abc', if my input was abc.
but when i just type in 'abc' in the command line, i get a return of abc (notice it does not have the quotation marks around it). My question is, how can i make it so that the contents i return from the textbox does not have those quotation marks around it, yet still a string type? Thanks
0 个评论
回答(5 个)
Jan
2011-9-20
The variable returned from the get command is a cell string. It does not contain the quotes, but they appear only, if you display the cell string in the command window.
Example:
s = 'abc';
disp(s)
>> abc
c = {'abc'};
disp(c)
>> 'abc'
% Display the contents of the first cell element:
disp(c{1})
>> abc
The cell string is useful to store multiple lines of the "textbox" - I assume it is a UICONTROL('Style', 'edit'). Look for "cell string" in the documentation to learn more about this topic.
7 个评论
Jan
2011-9-20
@Andy: I can only repeat: Please post the relevant part of the code. without seeing it, it is impossible to guess, what's going on.
Walter Roberson
2011-9-20
It is a bit complicated. The type of the value returned by get() of a String property depends upon how you set the string.
Read the descriptions of the various ways that the String property can be initialized for the various uicontrol Styles: http://www.mathworks.com/help/techdoc/ref/uicontrol_props.html#bqxoiqg
Now, if you initialized to a single string that (under the rules) would be interpreted as a single line, then get() of the String property will return a single line (i.e., a character row vector, also known as a string.)
If, though, you initialized to a padded array of strings, or if you initialized to a single string that contained '|' that (under the rules) were interpreted as line breaks, then get() of the String property will return a character array. (I do not recall at the moment whether I had found some exceptions that returned a cell array.)
If you initialized to a cell array of strings, then get() of the String property will return a cell array of strings.
Therefor, unless you are certain you know exactly how the String property was initialized, it is safest to test iscell() on the return value, and cellstr() if it was not already a cell.
1 个评论
Jan
2011-9-20
Using CELLSTR in all cases is safe: It does not change the data if it is a cell string already.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!