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

2 visualizaciones (últimos 30 días)
Eranja Noopehewa
Eranja Noopehewa el 23 de Mzo. de 2020
Comentada: Eranja Noopehewa el 24 de Mzo. de 2020
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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 23 de Mzo. de 2020
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 comentarios
Walter Roberson
Walter Roberson el 23 de Mzo. de 2020
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 el 24 de Mzo. de 2020
Thank You for the support given.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Import from MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by