Error => Unable to open file "Image1" for writing. You might not have write permission.
13 次查看(过去 30 天)
显示 更早的评论
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 个评论
Mridul Pandey
2017-11-18
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.
回答(2 个)
Adam
2017-3-16
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 个评论
Walter Roberson
2020-12-3
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)
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']);
Milad Kassaie
2022-8-3
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 个评论
Walter Roberson
2022-8-3
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.
See for example the use of tempdir() that Jan and I suggested, https://www.mathworks.com/matlabcentral/answers/330185-error-unable-to-open-file-image1-for-writing-you-might-not-have-write-permission#comment_437586
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
