Select parts of a string in MATLAB

4 views (last 30 days)
I have a character string that looks something like:
string =
The DOC for the 10 percent ROI = 332.45 dollars/pass
I want to retrieve only the '332.45' bit from it and I'm not sure how to go about it. I have a few possible ways I thought of (but am not sure how to implement):
1. I could select the characters based on where they appear wrt length of the string
2. I could select the characters based on the preceding string sequence.
I would need to repeat this several times since my file has some 1660 such values I need to retrieve.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 1 Oct 2013
Edited: Azzi Abdelmalek on 1 Oct 2013
EDIT
str =' The DOC for the 10 percent ROI = 332.45 dollars/pass'
out=regexp(str,'\d+\.\d+','match')
  2 Comments
Gautam Marwaha
Gautam Marwaha on 1 Oct 2013
Hey, thanks, this seems to work! It returns both '10' and '332.45'. How do I select just 332.45?

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!