Problems while exporting the data to excel file from MATLAB.

2 visualizaciones (últimos 30 días)
Pramul Panicker
Pramul Panicker el 31 de Mzo. de 2017
Respondida: Tushar Agarwal el 31 de Mzo. de 2017
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?

Respuestas (1)

Tushar Agarwal
Tushar Agarwal el 31 de Mzo. de 2017
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 .

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by