Cannot open file "." for reading. You might not have read permission.
61 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
AK
el 14 de Mzo. de 2021
Respondida: PABISH
el 5 de Oct. de 2024
I am trying to loop through a file and read each image in turn. However, it keeps saying I dont have read permission.
How do I fix this? Thank you!
dataset = dir('/Users/Desktop/Image Dataset');
numFiles = length(dataset);
mydata = cell(1,numFiles);
for k = 1:numFiles
mydata{k} = imread(dataset(k).name);
axes(handles.axes1)
imshow(mydata{k})
end
0 comentarios
Respuesta aceptada
Steven Lord
el 14 de Mzo. de 2021
dataset = dir('/Users/Desktop/Image Dataset');
All the entries in dataset (including the '.' and '..' directories) are relative to "/Users/Desktop/Image Dataset".
numFiles = length(dataset);
mydata = cell(1,numFiles);
for k = 1:numFiles
mydata{k} = imread(dataset(k).name);
There are at least two problems with this line.
1) You're not trying to read the data files from "/Users/Desktop/Image Dataset", you're trying to read them from somewhere on the MATLAB search path. Use the fullfile function to include the path name in the input to imread. This contributes partly to MATLAB being unable to find the file. But the main reason is:
2) You're assuming all the entries in dataset refer to image files. That output from dir will contain at least two elements that aren't, the aforementioned '.' and '..' directories. To resolve this you can prune all entries that refer to directories from dataset before calculating numFiles.
dataset = dataset(~[dataset.isdir]);
Continuing on with the rest of your code:
axes(handles.axes1)
imshow(mydata{k})
Are you sure you want to do this? Unless this is a simplified version of your problem, the image in mydata{1} will at most flicker on the screen for as long as it takes MATLAB to read the data for the second file. [In actuality, it probably won't even show for that long since there's no drawnow command in your loop.]
end
9 comentarios
Rik
el 15 de Mzo. de 2021
Use the debugger: what is the value of full_path at the point the error occurs? Can you see what could cause Matlab to be confused about the file format?
Más respuestas (1)
PABISH
el 5 de Oct. de 2024
when i tried running this simulation it shows, file cannot be opened for reading. what should i do?
0 comentarios
Ver también
Categorías
Más información sobre File Operations 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!