필터 지우기
필터 지우기

Why am I getting writing permission error using imwrite with this filename?

조회 수: 3 (최근 30일)
Alan Hidalgo
Alan Hidalgo 2017년 1월 5일
편집: Jan 2017년 1월 5일
Good morning. I've been trying to make the code below generate an image from a plot. The image should be a jpg file with the date and the hour as the filename. Nevertheless, matlab keeps showing me an error stating that I cannot write the file for I don't have the permissions. I've already checked the folder permissions and I'm allowed to do everything including writing. If I use a fixed filename then the code works fine but that's not the point. This is my code:
function Untitled_4_Callback(hObject, eventdata, handles) % hObject handle to Untitled_6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % guidata(handles.pushbutton2, handles); % --- Executes on button press in pushbutton1.
% No need to call guidata to obtain a structure; % it is provided by GUIDE via the handles argument % % handles.data=epsilon; % guidata(hObject, handles);
% save the changes to the structure
% writetable(epsilon) timex=handles.data; date=datestr(now); date=strread(date,'%s','delimiter',' '); dateday=date{1}; datetime=date{2}; datetime(strfind(datetime, ':')) = [';']; dater=[dateday,' ',datetime]; dater=mat2str(dater);
xlswrite(dater,timex); end
% --- Executes on button press in pushbutton9. function pushbutton9_Callback(hObject, eventdata, handles) % set(handles.pushbutton2,'Enable','on'); warndlg('Está a punto de borrar sus datos ¿Desea Proceder? Actualice dispositivos después de Borrar.','!! Advertencia !!') uiwait set(handles.pushbutton2,'string','Iniciar'); set(handles.pushbutton8,'Enable','on'); set(handles.popupmenu4,'Enable','on'); instrreset cla timed=[]; set(handles.uitable1,'Data',timed); clear all end
% -------------------------------------------------------------------- function uipushtool1_ClickedCallback(hObject, eventdata, handles) % hObject handle to uipushtool1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % timex=handles.data; date=datestr(now); date=strread(date,'%s','delimiter',' '); dateday=date{1}; datetime=date{2}; % datetime(strfind(datetime, ':')) = [';']; dater=[dateday,' ',datetime]; dater=mat2str(dater); M=dater; M=mat2str(M); M = regexprep(M, '''', ''); disp(M) ax = gca; ax.Units = 'pixels'; pos = handles.axes1.Position; ti = handles.axes1.TightInset; rect = [-ti(1), -ti(2), pos(3)+ti(1)+ti(3), pos(4)+ti(2)+ti(4)]; F = getframe(ax,rect); Image = frame2im(F); %Especificar en la laptop la carpeta contenedora % folder = 'C:\Users\Alan\Desktop\IMT PIC'; imwrite(Image,'jpg'); end
The error is this
Error using imwrite (line 454) Unable to open file "05-Jan-2017 10:06:49" for writing. You might not have write permission.
Error in Guigraficaserial>uipushtool1_ClickedCallback (line 700) imwrite(Image,M,'jpg');
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in Guigraficaserial (line 43) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)Guigraficaserial('uipushtool1_ClickedCallback',hObject,eventdata,guidata(hObject))
Error using dos Error while evaluating PushTool ClickedCallback
The files are supposed to be written in my desktop. I've searched for alternative functions on the documentation and found none. I also searched for answers on this forum, all of them adressed to the lack of permissions, some of them suggested to change the order of the arguments of the imwrite function; I tried them all without success. I also tried changing the format from jpg to bmp without results. Any help would be appreciated.
PD: By the way, the code option in the wizard just writes some code in the pad, it won't let me write mine with the correct format. If anyone told me how to do so it would be great :)
  댓글 수: 1
Jan
Jan 2017년 1월 5일
편집: Jan 2017년 1월 5일
The code is not readable without formatting (have you seen the "{} Code" button?), but it does not matter at all, because it is nor relevant for the problem. Only the file name matters.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2017년 1월 5일
편집: Jan 2017년 1월 5일
File names cannot contain ":" characters in Windows. Use another character as a delimiter to the time.
M = datestr(now, 'dd-mmm-yyyy HH_MM_SS')

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by