changing 'daytime' data type to string string to export in excel

I am trying to export sensor data with its associated date and time to excel sheet but due to some reason the date is not getting displayed in excel sheet or in workspace. code:
filename='xbee1.xlsx';
d{1,1}='Date';
d{1,2}='Sensor Data';
c=clock;
c=round(c);
t = datetime(c(1),c(2),c(3));
data_sensor{1,1}=t;
data_sensor{1,2}=rand;
d=[d; data_sensor];
disp(d);
%xlRange = sprintf('A%i:G%i',j,k);
xlRange = 'A1';
xlswrite(filename,d,1,xlRange);
Thanks in advance..

 채택된 답변

Peter Perkins
Peter Perkins 2015년 4월 24일
If the datetimes are in a table, writetable will just work:
>> Date = dateshift(datetime,'start','second') + seconds(0:4)';
>> SensorData = rand(5,1);
>> t = table(Date,SensorData)
t =
Date SensorData
____________________ __________________
24-Apr-2015 19:13:13 0.0357116785741896
24-Apr-2015 19:13:14 0.849129305868777
24-Apr-2015 19:13:15 0.933993247757551
24-Apr-2015 19:13:16 0.678735154857773
24-Apr-2015 19:13:17 0.757740130578333
>> writetable(t,'xbee2.xlsx')
You'll have to go into the spreadsheet and set the formatting, but you do gets the right dates/times. (Note that datetime('now'), or just datetime, is probably simpler than calling clock and converting, although you'd have to use dateshift to round to whole seconds.)
Or, use char or cellstr on your datetimes.
Hope this helps.

추가 답변 (1개)

Yash Mardikar
Yash Mardikar 2015년 4월 29일

0 개 추천

Thanks Peter,
But i used this insted
c=round(clock);
strcat(num2str(c(4)),':',num2str(c(5)),':',num2str(c(6)));

카테고리

도움말 센터File Exchange에서 Numeric Types에 대해 자세히 알아보기

제품

질문:

2015년 4월 23일

답변:

2015년 4월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by