How to save excel files as the curent date? Help
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello Everyone,
In my programme, I gather information about a set of pictures and then put the information into an excel file with the column headers 'Image', 'Number of Black pixels', 'Time', 'Status', 'Date'. This all works fine and the data gets saved correctly using xlswrite. However, I want to make a system where my programme creates a folder named with the current month (e.g "August") which I can do with mkdir maybe? Then, I want my MatLab programme to search my computer. If there is a folder with the current month then save the excel file into that folder. I want all excel files done within the same month to be on one spreadsheet but as different 'sheets'? How can I call these sheets by the date and time? (dd/mm/yyyy hh.mm.ss???) Furthermore, if my computer doesn't contain a folder with the current month and year, I want matlab to create one and save all the excel files for that month in there?
Can somebody please help? The basic help I need is how to incorporate the 'date(now)' or 'datevec' syntax's into the xlxwrite syntax?
Here is the current segment of code I use:
PhotoDetails={fullFileName, black, time, Status, Date}; %Date variable here will save the exact time and date the images were processed in answer to line 228 and 234.
Matrix(k,:)=PhotoDetails; %Matrix of three variables produced.
guidata(hObject,handles);
end
end
mkdir('c:\\AHT Results');
Header={'Image', 'Number of Black Pixels', 'Time (Seconds)', 'Status', 'Date'}; %Headers that will appear in adjacent cells on excel spread.
xlswrite((['c:\\AHT Results', date]), Header, num2str(date));
xlRange='A2';
xlswrite((['c:\\AHT Results', date]), Matrix, num2str(date), xlRange); %%Edit 'results' to current date function including seconds so it saves as new tab in monthly workbook.
This returns the error: Error using xlswrite (line 219)
Error in GUI_3_Beta>pushbutton4_Callback (line 280) xlswrite((['c:\\AHT Results', date]), Header, num2str(date));
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in GUI_3_Beta (line 42) gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)GUI_3_Beta('pushbutton4_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
Many thanks ,
Ellis
0 commentaires
Réponses (1)
Geoff Hayes
le 18 Août 2016
Ellis - it isn't all that clear what the xlswrite error might be, but you could consider building your file name with fullfile to ensure that it is valid as
myDir = 'C:\\AHT Results';
myFile = [date '.xlsx'];
pathAndFilename = fullfile(myDir,myFile);
xlswrite(pathAndFilename,...);
I'm not sure if that will fix the problem but hopefully any subsequent errors will be more descriptive.
datestr(now,'yyyy-mm-dd_HH:MM:SS')
returns
'2016-08-18_11:57:55'
4 commentaires
Guillaume
le 18 Août 2016
No, the date function is guaranteed (according to the doc) to return the date in the format day-month-year, but I assumed that date is actually a variable shadowing the function. Otherwise, there's no need for num2str.
Voir également
Catégories
En savoir plus sur Dates and Time dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!