Hi,
I am wonderinh whether I can write something like this:
If any(ismember(result , [" nafor", "kform", "acet"]))

 채택된 답변

meghannmarie
meghannmarie 2019년 10월 3일
편집: meghannmarie 2019년 10월 3일

0 개 추천

if you are trying to match string to string, try this:
if any(contains([' nafor','kform','acet'],result))

댓글 수: 5

Muazma Ali
Muazma Ali 2019년 10월 3일
as I have written I am dealing with string vectors here, not single string.
The vector may contain one of the mentioned strings that the if statement has to investigate
meghannmarie
meghannmarie 2019년 10월 3일
편집: meghannmarie 2019년 10월 3일
Maybe I do not undertsand your question, this gives me a true answer for your if statement to investigate.
result = ["kform","acet","other"];
if any(contains({' nafor','kform','acet'},result))
...
end
Muazma Ali
Muazma Ali 2019년 10월 3일
Thanks I understand it now.
Stephen23
Stephen23 2019년 10월 4일
편집: Stephen23 2019년 10월 4일
Note that [] is a concatenation operator, so this code:
[' nafor','kform','acet']
is just a complex way of writing this:
' naforkformacet'
Perhaps you actually intended to define strings, rather than character vectors?
Muazma Ali
Muazma Ali 2019년 10월 4일
No i was thinking of character vectors and I got my answer yesterday that I accepted :)

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

추가 답변 (0개)

카테고리

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

질문:

2019년 10월 3일

댓글:

2019년 10월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by