I'm not sure why what I wrote isn't working in terms of extracting the string I want.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Khanh Nguyen
am 24 Jun. 2018
Kommentiert: Walter Roberson
am 24 Jun. 2018
I have:
filename = Synch_ab001.mat;
underscore_indices = strfind(filename, '-');
period_indices = strfind(filename, '.');
SubjectName = strtok(filename(underscore_indices(end)+1:period_indices(end)-1));
I wrote this to extract just the ab001 as SubjectName, but I keep getting a "subscript indices must either be real positive integers or logicals."
1 Kommentar
Walter Roberson
am 24 Jun. 2018
Please do not close questions that have an answer. If you are satisfied with one of the solutions offered, Accept that answer.
Akzeptierte Antwort
Paolo
am 24 Jun. 2018
filename = 'Synch_ab001.mat';
subjectname = regexp(filename,'(?<=_)(.*)(?=\.\w*)','match')
0 Kommentare
Weitere Antworten (2)
Image Analyst
am 24 Jun. 2018
First of all filename is not a string. That should have thrown an error right away. Even if it were a string, you're looking for dashes and there are no dashes in the name. Try looking for underscores:
filename = 'Synch_ab001.mat';
underscore_indices = strfind(filename, '_')
period_indices = strfind(filename, '.')
SubjectName = strtok(filename(underscore_indices(end)+1:period_indices(end)-1))
0 Kommentare
Walter Roberson
am 24 Jun. 2018
filename = 'Synch_ab001.mat';
temp = regexp(filename, '[_.]', 'split');
subjectname = temp{2};
0 Kommentare
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!