Effacer les filtres
Effacer les filtres

converting indices into time

4 vues (au cours des 30 derniers jours)
AT_HYZ
AT_HYZ le 20 Juil 2023
Commenté : Adam Danz le 20 Juil 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

Réponse acceptée

Star Strider
Star Strider le 20 Juil 2023
Modifié(e) : Star Strider le 20 Juil 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 commentaire
Adam Danz
Adam Danz le 20 Juil 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)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Simulink dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by