필터 지우기
필터 지우기

I don't need to add a path if the picture file is in the same directory as my matlab file right?

조회 수: 1 (최근 30일)
I am in a directory with project1.m and guitar.jpg. But when I try to run this line in the command window I get "File "guitar.jpg" does not exist."
>> guitar = imread('guitar.jpg');
  댓글 수: 3
Rik
Rik 2021년 9월 10일
Since Matlab searches the same folders when looking for functions as it does when looking for files, there is no obvious reason for your error. Unless the file doesn't have the exact name you entered.
Walter Roberson
Walter Roberson 2021년 9월 10일
What shows up if you do
if ispc()
projectdir = '.';
else
projectdir = fullfile(matlabroot, 'toolbox', 'images', 'imdata');
end
cd(projectdir)
dinfo = dir('*.jpg');
filenames = {dinfo.name};
n = length(filenames);
fprintf('%d files found:\n\n', n);
38 files found:
for K = 1 : n
fprintf('|%s| which is character codes: %s\n', filenames{K}, mat2str(double(filenames{K})));
end
|baby.jpg| which is character codes: [98 97 98 121 46 106 112 103] |car1.jpg| which is character codes: [99 97 114 49 46 106 112 103] |car2.jpg| which is character codes: [99 97 114 50 46 106 112 103] |car_1.jpg| which is character codes: [99 97 114 95 49 46 106 112 103] |car_2.jpg| which is character codes: [99 97 114 95 50 46 106 112 103] |car_3.jpg| which is character codes: [99 97 114 95 51 46 106 112 103] |car_4.jpg| which is character codes: [99 97 114 95 52 46 106 112 103] |colorCheckerTestImage.jpg| which is character codes: [99 111 108 111 114 67 104 101 99 107 101 114 84 101 115 116 73 109 97 103 101 46 106 112 103] |eSFRTestImage.jpg| which is character codes: [101 83 70 82 84 101 115 116 73 109 97 103 101 46 106 112 103] |flamingos.jpg| which is character codes: [102 108 97 109 105 110 103 111 115 46 106 112 103] |foggyroad.jpg| which is character codes: [102 111 103 103 121 114 111 97 100 46 106 112 103] |foggysf1.jpg| which is character codes: [102 111 103 103 121 115 102 49 46 106 112 103] |foggysf2.jpg| which is character codes: [102 111 103 103 121 115 102 50 46 106 112 103] |foosball.jpg| which is character codes: [102 111 111 115 98 97 108 108 46 106 112 103] |football.jpg| which is character codes: [102 111 111 116 98 97 108 108 46 106 112 103] |greens.jpg| which is character codes: [103 114 101 101 110 115 46 106 112 103] |hallway.jpg| which is character codes: [104 97 108 108 119 97 121 46 106 112 103] |hands1.jpg| which is character codes: [104 97 110 100 115 49 46 106 112 103] |hands2.jpg| which is character codes: [104 97 110 100 115 50 46 106 112 103] |indiancorn.jpg| which is character codes: [105 110 100 105 97 110 99 111 114 110 46 106 112 103] |llama.jpg| which is character codes: [108 108 97 109 97 46 106 112 103] |lowlight_1.jpg| which is character codes: [108 111 119 108 105 103 104 116 95 49 46 106 112 103] |lowlight_2.jpg| which is character codes: [108 111 119 108 105 103 104 116 95 50 46 106 112 103] |micromarket.jpg| which is character codes: [109 105 99 114 111 109 97 114 107 101 116 46 106 112 103] |office_1.jpg| which is character codes: [111 102 102 105 99 101 95 49 46 106 112 103] |office_2.jpg| which is character codes: [111 102 102 105 99 101 95 50 46 106 112 103] |office_3.jpg| which is character codes: [111 102 102 105 99 101 95 51 46 106 112 103] |office_4.jpg| which is character codes: [111 102 102 105 99 101 95 52 46 106 112 103] |office_5.jpg| which is character codes: [111 102 102 105 99 101 95 53 46 106 112 103] |office_6.jpg| which is character codes: [111 102 102 105 99 101 95 54 46 106 112 103] |parkavenue.jpg| which is character codes: [112 97 114 107 97 118 101 110 117 101 46 106 112 103] |peacock.jpg| which is character codes: [112 101 97 99 111 99 107 46 106 112 103] |sevilla.jpg| which is character codes: [115 101 118 105 108 108 97 46 106 112 103] |sherlock.jpg| which is character codes: [115 104 101 114 108 111 99 107 46 106 112 103] |strawberries.jpg| which is character codes: [115 116 114 97 119 98 101 114 114 105 101 115 46 106 112 103] |trailer.jpg| which is character codes: [116 114 97 105 108 101 114 46 106 112 103] |wagon.jpg| which is character codes: [119 97 103 111 110 46 106 112 103] |yellowlily.jpg| which is character codes: [121 101 108 108 111 119 108 105 108 121 46 106 112 103]
The character codes allow you to check what character codes are really in the file name. For example there might be a space in the file name, which would show up as code 32. Or there might be a non-breaking zero-width whitespace character, which would show up as a code 8203 https://en.wikipedia.org/wiki/Zero-width_space

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

답변 (1개)

Image Analyst
Image Analyst 2021년 9월 10일
It should work. Check the spelling. Are you on a mac? Maybe it's guitar.jpeg. Try this:
fileList = dir('g*.*') % Listing of all files starting with g.
fileNames = {fileList.name} % Extract all names from structure into cell array.
What do you see in the command window?

카테고리

Help CenterFile Exchange에서 Search Path에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by