How can you read a filename but store a specific number within it?

조회 수: 1 (최근 30일)
Teshan Rezel
Teshan Rezel 2020년 5월 5일
댓글: Teshan Rezel 2020년 5월 5일
Hi All,
I'm trying to analyse a bunch of files that have filenames like "1 crop 1, area - 122637", "1 crop 2, area - 88497" etc.
I need to store the numbers proceeding "area - " as a number and sum them for all the files within a folder.
Is this possible?
Thanks
  댓글 수: 2
Stephen23
Stephen23 2020년 5월 5일
편집: Stephen23 2020년 5월 5일
'I need to store the numbers proceeding "area - " '
The word preceeding means "in front of". Do you really mean "following" ?
Which numbers do you want?
  • 1 & 2 (i.e. preceeding area)
  • 122637 & 88497 (i.e. following area)
What file extension do these files have?
Teshan Rezel
Teshan Rezel 2020년 5월 5일
hi Stephen, thanks for responding. "Proceeding" can also mean "originating from" and can be considered the opposite to "preceed". Apologies for the confusion!
To clarify, I used the word in the same context you have used the word "following"...so the latter case in your examples.
They have a .jpg file extension.
Many Thanks!

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

채택된 답변

Stephen23
Stephen23 2020년 5월 5일
편집: Stephen23 2020년 5월 5일
D = 'path to the folder where the files are saved';
S = dir(fullfile(D,'*crop*area*.jpg'));
[~,N] = cellfun(@fileparts,{S.name},'uni',0);
V = str2double(regexp(N,'\d+$','match','once'));
Z = sum(V)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by