MATLAB Answers

Error in extract_db (line 47) file_a = extractAft​er(char(fi​le_a), 0, strfind(char(file_a), '_')-2);

1 view (last 30 days)
'101_1.tif' '101_2.tif' '101_3.tif' '101_4.tif' '101_5.tif' '101_6.tif' '101_7.tif' '101_8.tif' '102_1.tif' '102_2.tif' '102_3.tif' '102_4.tif' '102_5.tif' '102_6.tif' '102_7.tif' '102_8.tif' '103_1.tif' '103_2.tif' '103_3.tif' '103_4.tif' '103_5.tif' '103_6.tif' '103_7.tif' '103_8.tif' '104_1.tif' '104_2.tif' '104_3.tif' '104_4.tif' '104_5.tif' '104_6.tif' '104_7.tif' '104_8.tif' '105_1.tif' '105_2.tif' '105_3.tif' '105_4.tif' '105_5.tif' '105_6.tif' '105_7.tif' '105_8.tif' '106_1.tif' '106_2.tif' '106_3.tif' '106_4.tif' '106_5.tif' '106_6.tif' '106_7.tif' '106_8.tif' '107_1.tif' '107_2.tif' '107_3.tif' '107_4.tif' '107_5.tif' '107_6.tif' '107_7.tif' '107_8.tif' '108_1.tif' '108_2.tif' '108_3.tif' '108_4.tif' '108_5.tif' '108_6.tif' '108_7.tif' '108_8.tif' '109_1.tif' '109_2.tif' '109_3.tif' '109_4.tif' '109_5.tif' '109_6.tif' '109_7.tif' '109_8.tif' '110_1.tif' '110_2.tif' '110_3.tif' '110_4.tif' '110_5.tif' '110_6.tif' '110_7.tif' '110_8.tif'
I have the Img names "101_1",
and I want to extract the substring
included between the underscore '_'.
Here I used,
file_a = extractAfter(char(file_a), 0, strfind(char(file_a), '_')-2);
but it produces error,
I want as output 102_1 and so on.
How can I do this? thanks

  0 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 21 Nov 2018
fileparts()
You do not indicate what the error is .I suspect you are using r2016a or earlier before extractAfter existed

  6 Comments

Show 3 older comments
Walter Roberson
Walter Roberson on 21 Nov 2018
file_a = regexprep(file_a, '\..*$', '');
This will work whether file_a is a cell array of character vectors or a single character vector -- in other words it can be applied to the complete list of filenames all at the same time.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!