Filter löschen
Filter löschen

converting indices into time

4 Ansichten (letzte 30 Tage)
AT_HYZ
AT_HYZ am 20 Jul. 2023
Kommentiert: Adam Danz am 20 Jul. 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

Akzeptierte Antwort

Star Strider
Star Strider am 20 Jul. 2023
Bearbeitet: Star Strider am 20 Jul. 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 Kommentar
Adam Danz
Adam Danz am 20 Jul. 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)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Simulink finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by