0

I want to copy some part of a string from a cell array and put it into another cell array in MATLAB.

For example, one struct is like this

{>eco:b0002 thrA; Bifunctional aspartokinase/homoserine dehydrogenase 1 (EC:1.1.1.3 2.7.2.4); K12524 bifunctional aspartokinase / homoserine dehydrogenase 1 [EC:2.7.2.4 1.1.1.3] (N) atgcgagtgttgaa...}, 

I want to paste the

'>eco:b0002 thrA; Bifunctional aspartokinase/homoserine dehydrogenase 1 (EC:1.1.1.3 2.7.2.4); K12524 bifunctional aspartokinase / homoserine dehydrogenase 1 [EC:2.7.2.4 1.1.1.3] (N)' 

part of referring string into another cell array.

In each cell it begins with '>' and ends up with '(N)', as you see one of them in the example.

I can't find any helpful function to start with.

2 Answers 2

1
>> str = '>eco:b0002 thrA; (N) atgcgagtgttgaa...';
>> result = regexp(str, '\>.+\(N\)', 'match');
>> result = result{1}
result =
>eco:b0002 thrA; (N)
Sign up to request clarification or add additional context in comments.

Comments

0

You want to use a regular expression.

Try for example:

> str = "> fooooo (N) bar baz"
> exp = "^>(.*)\\(N\\).*$"
> [tokens, matches] = regexp(str, exp, 'tokens', 'match')
> tokens{1}{1}
ans => foooooo

(Disclaimer: I tried the above in Octave, which should behave exactly the same).

3 Comments

I got an error in Matlab (even with single quotes instead of double qoutes). tokens is returned as empty
Unfortunately I do not have a MATLAB installation at hand to experiment with the finer details of MATLAB's regexp dialect, but I see it's no longer necessary :)
I didn't see anything obvious to correct/suggest in your answer, so I wrote mine :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.