필터 지우기
필터 지우기

How do I find a file name containing a particular string in a given directory and read this present file and write into other folder.

조회 수: 225 (최근 30일)
i have folder in this different .jpg files are present with specified name. i want to read file with particular name not fullfile name .
like in folder i have AKS_9129.jpg file present but i want to read with 9129.jpg name . not include AKS_9129.jpg
path15 = strcat('E:\folder\',num2str(9129),'.jpg');
im15 = imread(path15);
error occured file is not found.
i have enclosed folder structure.

답변 (2개)

Amirali Kamalian
Amirali Kamalian 2019년 8월 21일
You can make the code simpler by replacing this line
X = ~cellfun('isempty',strfind(N,num2str(9129)));
with
X = contains(N,num2str(9129));

Stephen23
Stephen23 2017년 9월 27일
편집: Stephen23 2017년 9월 27일
Method one: strfind:
P = 'E:\folder';
S = dir(fullfile(P,'*.jpg'));
N = {S.name};
X = ~cellfun('isempty',strfind(N,num2str(9129)));
I = imread(fullfile(P,N{X}))
Method two: dir:
P = 'E\folder';
F = sprintf('*%i*.jpg',9129);
S = dir(fullfile(P,F));
N = S.name;
I = imread(fullfile(P,N));
Note that in both cases you will need to check how many matching filenames there are. You should also read the MATLAB documentation:
and this forum, e.g.:
  댓글 수: 2
praveen chandaliya
praveen chandaliya 2017년 9월 27일
IF TWO FILE MATCH THAN THIS ERROR X =
1 0 0 0 1 0 0 0 0 0 0 0
Error using imread (line 349) File "E:\actualdata\9129.JPG\AKS_9129.jpg" does not exist.
Error in folderread (line 10) I = imread(fullfile(P,N{X})); HOW TO SOLVE THIS ERROR
Stephen23
Stephen23 2017년 9월 27일
편집: Stephen23 2017년 9월 27일
@praveen chandaliya: if two or more files match that number then you have to decide what to do. You might want to process both/all of them, or throw an error, or ignore them. How am I supposed to know what you want to do in that situation?
In any case I would highly recommend that you read the link to the documentation that I gave. The method you are trying to attempt is rather strange, and you would likely be much better off using one of the more standard ways to process a sequence of files.
The error message that you show tells me that you have used some different code than what I showed you, because in your error message 9129.JPG appears twice (did you read the message?):
E:\actualdata\9129.JPG\AKS_9129.jpg
My code does not do that, so you need to fix your code.

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

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by