Time format is changed to decimal when calling the time data from excel.
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Swathi
am 13 Jun. 2024
Beantwortet: Steven Lord
am 13 Jun. 2024
In matlab, when i read a time data (hh:mm:ss AM/PM) from excel, the time data becomes decimal number so unable to plot the time in x-axis in hh:mm:ss format. Kindly guide
0 Kommentare
Akzeptierte Antwort
Ganesh
am 13 Jun. 2024
time_in_decimal = readmatrix("TimeData.xlsx");
timeDuration = time_in_decimal * 24 * 60 * 60;
timeDuration = seconds(timeDuration);
sampleY = [1.75 12.2 4.67 9.2 19.1];
plot(timeDuration, sampleY);
xtickformat("hh:mm:ss");
xlabel('Time (hh:mm:ss)');
ylabel('Random Y-axis Label');
You can use the "xtickformat()" option to plot it in the required format.
Hope this helps!
Weitere Antworten (2)
Matlab Pro
am 13 Jun. 2024
Hi @Swathi
Another soltion using timeseries funciton
Have fun...
out = readtable('dates1.xlsx');
outFormat = 'hh:mm:ss AM';
vTime = out.time;
ts1 = timeseries(vData,vTime);
ts1.Name = 'Daily Count';
ts1.TimeInfo.Units = 'days';
ts1.TimeInfo.StartDate = '01-Jan-2011'; % Set start date.
ts1.TimeInfo.Format = 'HH:MM:SS AM'; % Set format for display on x-axis.
figure;plot(ts1)
0 Kommentare
Steven Lord
am 13 Jun. 2024
In matlab, when i read a time data (hh:mm:ss AM/PM) from excel,
How are you reading the data from the Microsoft Excel spreadsheet? Are you using the tools described on this documentation page?
If you're reading in multiple spreadsheets that are all formatted the same, I'd consider using the Import Tool (the second Related Topic on the documentation page to which I linked above) to interactively configure how MATLAB imports the data then generate a function file you can use to read in the second, third, fourth, etc. spreadsheets. I know Import Tool allows you to specify that you want to read individual variables in as datetime arrays (or other data types) rather than just as double arrays.
Alternately if you already have your data in MATLAB and don't want to re-import it, you could try turning those double arrays into a datetime array using the 'ConvertFrom' syntax with either 'excel' or 'excel1904' as the dateType input. See the "Convert Excel Date Number to Datetime" example on that documentation page.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!