I have the following text file which contains the following text lines: C:\Users\David\ab_1.obj
C:\Users\David\ab_5.obj
C:\Users\David\ab_300.obj
C:\Users\David\ab_27.obj
C:\Users\David\ab_233.obj
C:\Users\David\ab_1232.obj
C:\Users\David\ab_22.obj
I want to extract the numbers attached to the file names and the resulted numbers should stored in array
A=[1,5,22,27,233,300,1232]

 Accepted Answer

There are many ways of doing this, depending on what the criteria is for extracting the numbers (is it any number in the file? only those in the pattern ab_*.obj, something else?)
Anyway:
filecontent = fileread('yourfile.txt');
numbers = str2double(regexp(filecontent, '(?<=ab_)\d+(?=\.obj)', 'match'))

More Answers (0)

Categories

Asked:

on 6 Nov 2015

Answered:

on 6 Nov 2015

Community Treasure Hunt

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

Start Hunting!