Plot time in format 00:00:00

I am trying to plot time on the x-axis and on the y an amplitude (in this case 1 as an example) in the following format: however, following code breaks and an attempt to google led to datetime and prefixing that to the time format of not work nor did datestr
Plot([00:02:37.96469 00:02:38.93659], [1 1], bx)

4 comentarios

Adam Danz
Adam Danz el 16 de Ag. de 2019
@ nas , whenever you get an error message, please share the entire copy-pasted message (all of it). We need that info.
We also need to know what version of matlab you're using. You can check that by running ver().
What does your original data look like? How are you trying to convert it to datetime? You'll need to be much more descriptive about what you've tried and why it's not working.
The exact error message is: Input data must be a numerical matrix with three columns or three numerical Arrays
The Matlab version is 2017a.
There is no conversion. I am simply trying to generate a plot with time on the x axis and the y axis at 1.
The x axis has two simple time points as shown in my original post repeated here:
I need the x axis to be time proportional to its values
Plot([00:02:37.96469 00:02:38.93659], [1 1], bx)
Adam Danz
Adam Danz el 16 de Ag. de 2019
Look at this.
>> [00:02:37.96469 00:02:38.93659]
ans =
Columns 1 through 22
0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 0 2 4
Columns 23 through 39
6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38
Where did this ">> [00:02:37.96469 00:02:38.93659]<<" come from? Did you just type that in?
nas illmatic
nas illmatic el 16 de Ag. de 2019
Yes that’s the time I want to plot and yes I just typed that in

Iniciar sesión para comentar.

Respuestas (1)

Jess Lovering
Jess Lovering el 14 de Ag. de 2019

0 votos

Have you tried to use the duration function?
plot(duration({'00:02:37.96469', '00:02:38.93659'}), [1 1], 'bx')

8 comentarios

nas illmatic
nas illmatic el 16 de Ag. de 2019
I tried this today. However it does not work. It produces an error stating the duration function requires ‘three columns’
That was changed in later releases; in your release
duration(0, 2, [37,38], [96469,93659]/100)
Adam Danz
Adam Danz el 16 de Ag. de 2019
Editada: Adam Danz el 16 de Ag. de 2019
@nas, we need (much) more information.
The conversion Jessica provided is fully functional.
duration({'00:02:37.96469', '00:02:38.93659'})
ans =
1×2 duration array
00:02:37 00:02:38
You mentioned "I just typed [the timestamps] in". If you typed them in as strings, this should work. We can't provide much help if we have no idea what type of data you're working with.
Could you show us your timestamps? The examples you showed previously are not matlab syntax.
Walter Roberson
Walter Roberson el 16 de Ag. de 2019
nas mentioned R2017a, at which time duration() did not accept character vectors for the time specification.
Adam Danz
Adam Danz el 16 de Ag. de 2019
Ah, I didn't catch that.
nas illmatic
nas illmatic el 17 de Ag. de 2019
Editada: nas illmatic el 17 de Ag. de 2019
I found a Matlab 2018b computer and yes, the first and the second commands (listed below) both work - Thanks. However, the only issue now is that the x-axis label does not populate correctly. It simply states "00:02:38" - It appears it is rounding to the nearest minute - anyway to have the x-axis show the seconds.
plot(duration({'00:02:37.96469', '00:02:38.93659'}), [1 1], 'bx')
plot(duration(0,2, [37,38],[96469,93659]/100),[1 1],'bx')
tr = duration(0,2, [37,38],[96469,93659]/100, 'Format', 'mm:ss.SSSSSS');
plot(tr, [1 1], 'bx')
I use 2019a so I am not sure if this will be the same, but I am able to change the x-axis format with this command:
h = gca;
h.XAxis.TickLabelFormat = 'mm:ss.SSSSSS';

Iniciar sesión para comentar.

Categorías

Productos

Versión

R2017a

Etiquetas

Preguntada:

el 14 de Ag. de 2019

Comentada:

el 19 de Ag. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by