I don't need to add a path if the picture file is in the same directory as my matlab file right?
조회 수: 3 (최근 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
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
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);
for K = 1 : n
fprintf('|%s| which is character codes: %s\n', filenames{K}, mat2str(double(filenames{K})));
end
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
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?
댓글 수: 1
참고 항목
카테고리
Help Center 및 File Exchange에서 Audio and Video Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!