MATLAB: Part of file name MATLABpart of the nameregexp If I have a file name such as ' Hello_World_2020 ', I want to take the part between the underscores ' world ', how I would do that. Regards. Best Answer s = 'Hello_World_2020';c = regexp(s, '_', 'split') ;c{2}You can also use strsplit() instead of regexp. On the other hand, strsplit() invokes regexp internally. Related SolutionsMATLAB: Making upper case character with respect to the indexes Try this:indxC = [1,7];s ='hello world';s(indxC) = upper(s(indxC))or more generally:s ='hello world';upperS = upper(s); % Create an ALL CAPITALS VERSION of s.spaceLocations = find(s(1:end-1) == ' '); % Find spaces - we'll capitalize the location after a space.spaceLocations = [0, spaceLocations] % Always capitalize the first letter, so prepend 0.s(spaceLocations + 1) = upperS(spaceLocations + 1) % Replace these locations with upper case letters. MATLAB: Extracting numbers from mixed string s = '2001_06m';d = sscanf(s, '%d_%d')ans = 2001 6Easier and faster than regexp.[EDITED] If the input is a cell string:C = {'2001_06m', '002_77q'};S = sprintf('%s ', C{:});S(S < '0' | S > '9') = ' '; % Mask all non-numbersNum = sscanf(S, '%d %d ', [2, Inf]); Related QuestionExtract Last two Words from strings in cellInitial position of vrml scene when run new simulationEfficient way to use regexp and contains and matchingReading numeric part of line n MATLAB
Best Answer