Time format is changed to decimal when calling the time data from excel.
조회 수: 12 (최근 30일)
이전 댓글 표시
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
채택된 답변
Ganesh
2024년 6월 13일
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!
추가 답변 (2개)
Matlab Pro
2024년 6월 13일
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
Steven Lord
2024년 6월 13일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!