So I know that this will be a simple fix, I am not very familiar with Matlab.
I am trying to read in a picture using imread using this code...
path = 'C:\Users\chris\Documents\Homework\ThermoFluids\Sphere Drag\Orange1_C001H001S0001';
Directory = dir([path '/*.tif']);
picture = imread(Directory(1).name);
imshow(picture);
Those are all .tif files. This code was working for an adjacent folder and I can't figure out why it isn't working for this folder.
The error matlab is giving me is shown below...
Error using imread>get_full_filename (line 566)
File "Orange1_C001H001S0001000001.tif" does not exist.
Error in imread (line 375)
fullname = get_full_filename(filename);
Error in SphereDrag (line 7)
picture = imread(Directory(1).name);
>>

 채택된 답변

Image Analyst
Image Analyst 2019년 10월 27일

2 개 추천

The problem is that you're not prepending the folder to the base file name so it will look only in the current folder (of your m-file) or on the search path. To have it find the file that is not there, you must give the full file name by prepending the folder.
And do NOT use path as the name of your folder since it's the name of a very improtant built-in variable.
folder = 'C:\Users\chris\Documents\Homework\ThermoFluids\Sphere Drag\Orange1_C001H001S0001';
fileList = dir(fullfile(folder, '/*.tif'));
fullFileName = fullfile(fileList(1).folder, fileList(1).name)
picture = imread(fullFileName);
imshow(picture);

댓글 수: 3

Chris Reid
Chris Reid 2019년 10월 27일
Thank you! This was very helpful!
suha alasheh
suha alasheh 2021년 3월 31일
i tried it but it gave me "Index exceeds the number of array elements (0)." error. What to do?
Walter Roberson
Walter Roberson 2021년 3월 31일
The folder you used did not exist or has no tif files directly in it.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2019년 10월 27일

1 개 추천

picture = imread( fullfile(path, Directory(1).name) );

카테고리

도움말 센터File Exchange에서 Search Path에 대해 자세히 알아보기

질문:

2019년 10월 27일

댓글:

2021년 3월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by