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?
另请参阅
类别
在 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!