Error => Unable to open file "Image1" for writing. You might not have write permission.

13 vues (au cours des 30 derniers jours)
Am getting an error "Unable to open file "Image1" for writing. You might not have write permission." while running this program. Please help me
x=videoinput('winvideo',1);
for i=1:10
preview(x);
pause(1);
img=getsnapshot(x);
fname=['Image' num2str(i)];
imwrite(img,fname,'jpg');
pause(0.1);
end
  1 commentaire
Mridul Pandey
Mridul Pandey le 18 Nov 2017
change present working directory to the desired directory where you want to save the file either change in on the command window or script. like.. cd c:\folder\folder\... and then use imsave(...) function.

Connectez-vous pour commenter.

Réponses (2)

Adam
Adam le 16 Mar 2017
Surely the error is self-explanatory? How exactly are you expecting us to give you write access to your folder? Can you open other files from that folder? Can you create new files in it outside of Matlab?
  3 commentaires
Walter Roberson
Walter Roberson le 3 Déc 2020
img = randi([0 255], 320, 240, 3, 'uint8');
imshow(img)
i = 7;
folder = tempdir; % Adjust to your needs
fname = fullfile(folder, ['Image' num2str(i)]);
imwrite(img,fname,'jpg');
dir(folder)
. GDS-CACHE hsperfdata_wguser worker.properties .. Image7 jetty-0.0.0.0-8080-worker-webapp-_-any- ws_override.properties Editor_dswgc hsperfdata_mcguser matlabpref
Image7 is present in the output directory. Looks to me as if it worked.
Note: most of the time you want to append a file extension to the file name, such as
fname = fullfile(folder, ['Image' num2str(i) '.jpg']);

Connectez-vous pour commenter.


Milad Kassaie
Milad Kassaie le 3 Août 2022
This is a common issue in MS Windows. Write access is restricted in system folders, including where MATLAB is typically installed.
The soultion is to close MATLAB. Then right-click on the MATLAB icon and choose "Run as Administrator". Matlab will now have write access everywhere.
I hope this helps.
  1 commentaire
Walter Roberson
Walter Roberson le 3 Août 2022
Run As Adminstrator is not recommended; the operating system restrictions are there to prevent malware from infecting the system, and to reduce accidental user corruption of files.
You should instead take care to write to a directory you have write access to.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by