Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datetick format 1

Status
Not open for further replies.

rm2

Mechanical
Jun 7, 2005
41
Hello,

I am importing some data from excel, on my file the format for the date is dd/mmm/yyyy HH:MM:SS.
Datetick format needs to have it dd-mmm-yyyy HH:MM:SS.

Can someone please help me on how can I convert it to the datetick format please.

thanks
 
Replies continue below

Recommended for you

There are two ways to do this.

(1) Easier

Change the date format in excel itself....

format cells-> select custom --> (type the format you need)

your case dd-mmm-yyyy HH:MM:SS

then read this file

(2) Round about way

lets say your excle file first column contians date in any format and second column contains numbers. Save the file in csv format and use textscan command(i believe you cannot read strings using xlsread command)


fid=fopen('FileName.csv','r');
fileformat='%s %f';
data=textscan(fid,fileformat,'headerlines',2,'delimiter',',');
fclose(fid);

Assuming your first and second rows contain some headings/units 'headerlines',2 will ignore first two rows.

Now 'Data' is a cell data type with Data{1} containing array of date strings

dateformat='dd-mmm-yyyy HH:MM:SS' % Could be any format

%====if you want to plot use
plot(Data{1},Data{2})
datetick(dateformat) % Will put your dates in required format on axis


% ==if you want to rewire formatted strings to excel file==

ReqDates=datestr(datenum(Data{1}),dateformat)
ReqDates will contain a string of dates in required format
you can drirectly write/overwrite these dates to you excel file using xlswrite('Filename.xls',ReqDates,'Worksheet','Range');


Hope this helps.

Nodal DOF


 
thanks Nodal and sompting
I will try it!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor