Azzera filtri
Azzera filtri

converting indices into time

4 visualizzazioni (ultimi 30 giorni)
AT_HYZ
AT_HYZ il 20 Lug 2023
Commentato: Adam Danz il 20 Lug 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

Risposta accettata

Star Strider
Star Strider il 20 Lug 2023
Modificato: Star Strider il 20 Lug 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 Commento
Adam Danz
Adam Danz il 20 Lug 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)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Simulink in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by