get command return types

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

답변 (5개)

Jan
Jan 2011년 9월 20일

0 개 추천

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

Andy
Andy 2011년 9월 20일
but the thing is when i have a list of them (i put the result from a bunch of textboxes in a cell, so i have a list), and then i compare it to if i enter those in manually (i.e. i enter into the code, not the command line), i get two different cell list, one with the quotation marks, and one without. This crashes my program because it requires comparison between two lists without the quotation marks. Thanks
Andy
Andy 2011년 9월 20일
when i try using the display command on my cell list, i get one with quotation marks
Jan
Jan 2011년 9월 20일
I do not understand. You have a list of what? What do you enter manually?
Again: The cell string does *not* have quotation marks. They are inserted just by the DISP command to allow for a distinction of {1} and {'1'}.
I assume you create a cell of cell strings. But this is pure guessing. It would be more clear if you post the relevant code and explain, what you want to achieve.
Andy
Andy 2011년 9월 20일
ok, i think i found out where the problem is, it is extracting the text boxes i want it to, but when i set another list as those variables from those list, it changes, when i say
list = mylist(1,1)
where list is the new list, and mylist is the list that i stored the variables from the text box in. both are type char, but list comes out with the apostrophe around them.
Jan
Jan 2011년 9월 20일
I still cannot follow. After "list = mylist(1,1)" list and mylist have the same type. Perhaps you wnat "mylist{1,1}" with curly braces?
Did you understand, that the quotes are not parts of the strings, but are shown only to increase the readability?
Andy
Andy 2011년 9월 20일
ok, if someone can explain what this error wants me to fix that be all i need...
???Error using ==>dataset.subsasgn at 1008
Value must be vector of class double
dataset.subsagn is a matlab inbuilt function. thanks
Jan
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.

댓글을 달려면 로그인하십시오.

Andy
Andy 2011년 9월 20일

0 개 추천

so i have
if strcmp (filelist(i).name(1:3), namelist(1,1)) gasclopt = namelist(2,1);
so when i pass namelist(2,1) into gasclopt is different from when this:
if strcmp (filelist(i).name(1:3), namelist(1,1)) gasclopt = 'ESSO'
because the first one gives me an error later on in other function, while the later doesnt

댓글 수: 5

Jan
Jan 2011년 9월 20일
What is the type of filelist? Perhaps you wnat "filelist{1}.name(1:3)"? Or is filelist comming from the DIR command? Then you would need: "{filelist(1:3).name}".
As I said already, try: "gasclopt = namelist{2,1};"
Jan
Jan 2011년 9월 20일
Using STCMP with a cell string replies a LOGICAL vector. Using vectors as condition in an IF statement inserts and ALL implicitely. It is safer to do this explicitely:
if all(strcmp(<cellstring>, <string>)) ...
Andy
Andy 2011년 9월 20일
when i do gasclopt = namelist{2,1}; it gives ???Conversion to char from cell is not possible
Andy
Andy 2011년 9월 20일
when i try filelist{1}.name(1:3), it says ???Cel contents reference from a non-cell array object
Jan
Jan 2011년 9월 20일
It would be easier to assist, if you explain the type of the data. The above errors are a result of the fact, that I can only guess the types.

댓글을 달려면 로그인하십시오.

Andy
Andy 2011년 9월 20일

0 개 추천

when i do gasclopt = namelist{2,1}; it gives ???Conversion to char from cell is not possible
Andy
Andy 2011년 9월 20일

0 개 추천

its fixed!
Walter Roberson
Walter Roberson 2011년 9월 20일

0 개 추천

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
Jan 2011년 9월 20일
Using CELLSTR in all cases is safe: It does not change the data if it is a cell string already.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

질문:

2011년 9월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by