extract decimal number from a file name
Show older comments
Hello everyone,
Firwstly, Happy new year.
I have have a file name such as '2C2C', sometimes the number has a fraction for example '2.5C3C' or 2.5C3.5C'. I need to exract these number at all cases (with fraction and without).
Thanks in advance
Accepted Answer
More Answers (2)
KSSV
on 4 Jan 2021
str = '2C2C' ;
str = '2.5C3C' ;
% str = '2.5C3.5C' ;
idx = strfind(str,'C') ;
num1 = str2num(str(1:idx(1)-1))
num2 = str2num(str(idx(1)+1:idx(2)-1))
1 Comment
Ayman Mounir
on 4 Jan 2021
The most efficient solution by far:
C = {'NNN_2.5C3C_BlaBla'; 'NNN_2.5C3.5C_BlaBla'};
M = sscanf([C{:}],'%*[^_]_%fC%fC_',[2,Inf]).'
1 Comment
Ayman Mounir
on 6 Jan 2021
Categories
Find more on Exploration and Visualization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!