# Extracting the numbers from file names and listing them in a column

조회 수: 1(최근 30일)
Babu Sankhi 2021년 1월 21일
댓글: Babu Sankhi 2021년 1월 22일
Hi all ,
I have png files like this ;
Rpma26siatBz 9.500000 Bx 0.000000mT WWait 2.000000Sec.Bzat9.5mT83.png,
Rpma26siatBz 9.500000 Bx 100.000000mT WWait 1.000000Sec.Bzat9.5mT85.png
and so on
I want to extract numbers 0.000000 from first file ,100.000000 from second file etc .and put in one column.
And again extract the numbers 2.000000 from first file,1.000000 from second file etc. and put in another column.
I tried writing the code like this but it didnt work ( I mean I got NAN)? It would be great if you share any ideas for doing it .
thank you
clear all;
close all;
clc;
listI=dir('*.png');
B=[];
for i=1:length(listI);
n=listI(i);
A1 =n(1:end-26);
A2 = n(1:end-19);
x1= str2double(A1);
x2=str2double(A2);
Bx=[B;(x1),(x2)];
end

댓글을 달려면 로그인하십시오.

### 채택된 답변

Stephen23 2021년 1월 21일
편집: Stephen23 2021년 1월 21일
C = {'Rpma26siatBz 9.500000 Bx 0.000000mT WWait 2.000000Sec.Bzat9.5mT83.png',...
'Rpma26siatBz 9.500000 Bx 100.000000mT WWait 1.000000Sec.Bzat9.5mT85.png'};
M = sscanf([C{:}],'Rpma%*dsiatBz%*f Bx%fmT WWait%fSec.Bzat%*fmT%*d.png',[2,Inf]).'
M = 2×2
0 2 100 1
Or
W = regexp(C,'(?<=\s)\d+\.\d+(?=[A-Za-z])','match');
M = str2double(vertcat(W{:}))
M = 2×2
0 2 100 1
##### 댓글 수: 5표시숨기기 이전 댓글 수: 4
Babu Sankhi 2021년 1월 22일

댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

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

Start Hunting!

Translated by