I don't need to add a path if the picture file is in the same directory as my matlab file right?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Rik
el 10 de Sept. de 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
el 10 de Sept. de 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
Respuestas (1)
Image Analyst
el 10 de Sept. de 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 comentario
Ver también
Categorías
Más información sobre Audio and Video Data en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!