Problems while exporting the data to excel file from MATLAB.

조회 수: 2 (최근 30일)
Pramul Panicker
Pramul Panicker 2017년 3월 31일
답변: Tushar Agarwal 2017년 3월 31일
I would like to ask you a help to solve an issue while exporting time data from matlab to excel file. The code I use is shown below
if true
% code
end
filename = 'C:\.....\myFile4.xlsx';
sheet = 1;
a = 1;
while a<20
d{a,1} = datestr(now,'HH:MM:SS');
d{a,2} = rand(1);
d{a,3} = rand(1);
d{a,4} = rand(1);
d{a,5} = 'String';
A ={d{a,1},d{a,2},d{a,3},d{a,4},d{a,5}};
xlRange = strcat('C',num2str(a)); % Set the cell location
xlswrite(filename,A,sheet,xlRange)
a = a+1;
end
The data is getting written in the excel file but the time values in the first coloum seems to be some fractional numbers. How can I get the time values written in the format 'HH:MM:SS' in the excel file?

답변 (1개)

Tushar Agarwal
Tushar Agarwal 2017년 3월 31일
Hello - the conversion is probably due to the fact that excel has a different starting timestamp in its history, and Matlab I think starts in 01-01-1900. These numbers represnt the number of seconds since the start of this particular date (as mentioned above). What you could do, is select the time stamp column on excel, and format it there - using the format option -> time -> and choose your preferred format.
Else - go ahead and export it as a table instead of an xlsx. It will still be an xlsx, but the timestamp doesnt get varied. check TABLE .

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by