필터 지우기
필터 지우기

plot a line graph with HH:MM:SS in X-axis

조회 수: 2 (최근 30일)
Eranja Noopehewa
Eranja Noopehewa 2020년 3월 23일
댓글: Eranja Noopehewa 2020년 3월 24일
I have imported excel data to matlab and i need to plot a line graph where my x axis is date and time in HH:MM:SS and Y axis is power in kW. My X-axis data is as follows.
How can I plot a line graph using this as my x axis? Becacuse when I plot using this, my graph becomes messy. But when I use my x-axis data as 1,2,3,4,5 etc instead of time and data values the graph becomes perfect.

채택된 답변

Walter Roberson
Walter Roberson 2020년 3월 23일
Use readtable to read in ss a datetime variable and a duration variable, and add the two together to get your x values. set the Format property of the result to appropriate, probably 'HH:mm:ss'. plot can use datetime objects as the x values without difficulty.
  댓글 수: 7
Walter Roberson
Walter Roberson 2020년 3월 23일
filename = 'ee.xlsx';
T = readtable(filename) ; %ignore the warning about modified column names
X = T{:,6} + days(T{:,4});
P1 = T{:,1};
P2 = T{:,2};
P3 = T{:,3};
plot(X, [P1, P2, P3]);
legend({'Power 1', 'Power 2', 'Power 3'});
I tested this on R2017a on Mac.
I suspect that you have problems with your Excel. In your release, readtable() on MS Windows will always try to form a connection to Excel to do the reading, and if Excel cannot be reached it will fall back to portable code that does not need Excel. You could end up with an internal error message like you saw if the attempt to reach Excel resulted in a problem.
For debugging purposes, would it be practical for you to uninstall Excel for now? That would enable readtable() to use its internal code to do the reading.
New enough versions of MATLAB now default to using the internal code unless you specifically tell it to use Excel; I think R2019b was the first release for that feature.
Eranja Noopehewa
Eranja Noopehewa 2020년 3월 24일
Thank You for the support given.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by