필터 지우기
필터 지우기

display image in subfolder of current folder

조회 수: 2 (최근 30일)
Preethi
Preethi 2015년 8월 23일
댓글: Preethi 2015년 8월 24일
hi,
I to display an image which is in one of the sub-folders of the current directory. I know the name of the file. how will i know which sub-folder it is in and how will i display in it???
thanking you in advance.

채택된 답변

Image Analyst
Image Analyst 2015년 8월 24일
Preethi, try this:
% Specify the top level folder.
topLevelFolder = 'C:\Users\Mark\Pictures';
% Add this folder and all of its subfolders to the search path.
addpath(genpath(topLevelFolder));
% Define the base file name of the file you are looking for.
baseFileName = 'anagrams.png';
% Display it. It will find it on the search path if it's there.
imshow(baseFileName);
  댓글 수: 1
Preethi
Preethi 2015년 8월 24일
I have used system() and check for the path in the output, got the result but process was tedious. What you have suggested is very simple, thank you

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

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2015년 8월 23일
filename='photo.jpg'; % your image
a=dir
b={a.name};
idx=cellfun(@isdir,b)
c=b(idx)
c=c(3:end)
for k=1:numel(c)
f=dir
ii=ismember(filename,{f.name})
if ii
im=imread(fullfile(pwd,f,filename))
figure
imshow(im)
break
end
end
  댓글 수: 1
Walter Roberson
Walter Roberson 2015년 8월 24일
Note: it is not guaranteed that "." and ".." will be the first two entries in the directory list. The order is arbitrary. You should be testing against the names, not against the positions.

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

카테고리

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