Why am I getting writing permission error using imwrite with this filename?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!