MATLAB: How to extract a specific 3 digit number from a filename

extractimage analysisMATLAB

I have this filename (hst_05773_05_wfpc2_f502n_wf_sci.tif) and i would like to extract the three digit number after the _f . i.e. 502, but i am not sure how to do that as i am a beginner in MATLAB Thanks in advance

Best Answer

s='hst_05773_05_wfpc2_f502n_wf_sci.tif'
out=regexp(s,'(?<=_f)\d{3}','match','once')
or
s='hst_05773_05_wfpc2_f502n_wf_sci.tif'
idx=strfind(s,'_f')
out=s(idx+2:idx+4)