Why are strings in a cellarray not interpreted as strings?

I'm sorry, but I'm sure this is a dumb question, so I ask your forgiveness in advance.
I have a cell array of strings. For example,
mystrings={'(2,3)(4,7)(5,9)', '(1,3)(4,9)'};
now I want to pass them, one at a time, to a function that takes a string argument. When I call
myfunction('(2,3)(4,7)(5,9)')
it works fine, but if I call
myfunction(mystrings(1))
it's not working because, aparently, mystrings(1) is not really a string, even though, when I type mystrings(1) on the matlab command line, the output is
'(2,3)(4,7)(5,9)'
Also, when I enter
isstr('(2,3)(4,6)(5,9)')
the answer is 1, but isstr(mystrings(1)) gives 0.
So what am I missing?
Thanks! -William

 채택된 답변

Teja Muppirala
Teja Muppirala 2011년 3월 5일
mystrings(1) returns a cell array.
mystrings{1} returns the actual contents of the cell array (in this case a string).
So you should do
myfunction(mystrings{1})

추가 답변 (1개)

James Tursa
James Tursa 2011년 3월 5일

1 개 추천

mystrings is a cell array, the elements of which are cells. The contents of the cells are strings. The ( ) syntax recovers the cell, the { } syntax (curly braces) recovers what is in the cell. e.g.,
mystrings(1) is a cell that is the first element of mystrings.
mystrings{1} is the contents of the above cell, and is a string.

댓글 수: 1

Thanks to you both for giving me such quick and helpful answers! -William

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by