Borrar filtros
Borrar filtros

converting indices into time

4 visualizaciones (últimos 30 días)
AT_HYZ
AT_HYZ el 20 de Jul. de 2023
Comentada: Adam Danz el 20 de Jul. de 2023
Hi,
I have attached my Matlab graph. I have 163000 indices for speed and sampling rate was 3000. I would like to convert the x-axis into time so it will be around 54 seconds.
could anyone help? thanks.
openfig figure1
ans =
Figure (1) with properties: Number: 1 Name: '' Color: [1 1 1] Position: [314 365 1184 495] Units: 'pixels' Show all properties

Respuesta aceptada

Star Strider
Star Strider el 20 de Jul. de 2023
Editada: Star Strider el 20 de Jul. de 2023
Try this —
F = openfig('figure1.fig');
Lines = findobj(F, 'Type','line');
tidx = Lines.XData;
speed = Lines.YData;
Fs = 3E+3; % Sampling Frequency (Hz)
tsec = tidx/Fs;
Lines.XData = tsec; % Set X-Axis To 'tsec'
Check = tsec(end)
Check = 54.3333
EDIT — (20 Jul 2023 at 10:47)
The ‘XData’ are currently indices, and in MATLAB, indexing begins at 1, not 0. To have the time axis vector begin at 0, subtract 1 from ‘tidx’ or equivalently:
Lines.XData = (Lines.XData-1)/Fs;
The last value is then 54.330.
.
  1 comentario
Adam Danz
Adam Danz el 20 de Jul. de 2023
Here's an extension to @Star Strider's solution that converts the xdata to seconds and changes the X-ruler to a DurationRuler where the tick labels will include the duration units (sec, in this case).
F = openfig('figure1.fig');
Lines = findobj(F, 'Type','line');
tidx = Lines.XData;
speed = Lines.YData;
Fs = 3E+3; % Sampling Frequency (Hz)
tsec = tidx/Fs/24/60/60; %
Lines.XData = tsec;
ax = ancestor(Lines,'axes');
set(ax,'XRuler',matlab.graphics.axis.decorator.DurationRuler)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Simulink en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by