I don't need to add a path if the picture file is in the same directory as my matlab file right?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Rik
le 10 Sep 2021
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
le 10 Sep 2021
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
Réponses (1)
Image Analyst
le 10 Sep 2021
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 commentaire
Voir également
Catégories
En savoir plus sur Audio and Video Data dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!