Info

この質問は閉じられています。 編集または回答するには再度開いてください。

field delimiter uses any char as to declare a new field instead of full string

1 回表示 (過去 30 日間)
Antonio
Antonio 2011 年 3 月 9 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hi all,
I've been having a problem with function strread (I also tried it with textscan, but the problem still).
Assume I have this line: str= 'Name=conserved hypothetical protein;description=null;locus=gene3654c'
I want to use as field delimiter 'locus='
Then, I would have as last field gene3654c.
I've been trying the following (and some variations): id = strread(str,'%s', 'delimiter', 'locus=')
However, the output of id becomes: id =
'Name'
''
''
'n'
'erved hyp'
'theti'
'a'
'pr'
'tein;de'
''
'ripti'
'n'
'n'
''
''
';'
''
''
''
''
''
'gene3654'
And it cuts the "c" of gene3654. But I don't want it.
I could solve this problem changing the way I parse my string. However, a question is still in my mind:
How do I use as full string as field delimiter? i.e., using as delimiter 'locus=', it should return: id = 'Name=conserved hypothetical protein;description=null;' 'gene3654c'

回答 (2 件)

Jiro Doke
Jiro Doke 2011 年 3 月 9 日
id = regexp(str, '(locus=)', 'split')
  2 件のコメント
Oleg Komarov
Oleg Komarov 2011 年 3 月 9 日
+1
Antonio
Antonio 2011 年 3 月 9 日
Thanks! I knew it should have a way to solve this problem.

Matt Fig
Matt Fig 2011 年 3 月 9 日
Just so you understand what happened when you set the delimiter to 'locus=', MATLAB interprets the delimiter property as a list of individual characters to use as delimiters. Thus each character in 'locus=' was used as a delimiter. Jiro showed you how to use REGEXP to specify 'locus=' as a delimiter. You could also get just the string following 'locus=' by using REGEXP:
regexp(str,'(?<=locus\=).*','match')
I am not sure what you mean by, "Then, I would have as last field Rv3654c." Where does the Rv come from?
  2 件のコメント
Jiro Doke
Jiro Doke 2011 年 3 月 9 日
Ah, good explanation about why it didn't work for strread.
I assumed "Rv" was a typo. At the end of the question, he has "gene3654c".
Antonio
Antonio 2011 年 3 月 9 日
Thanks!
Yes, Rv was a typo. Sorry about that.

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by