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
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
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
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)
. 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']);

请先登录,再进行评论。


Milad Kassaie
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
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by