converting indices into time
조회 수: 3 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Star Strider
2023년 7월 20일
편집: Star Strider
2023년 7월 20일
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)
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
Adam Danz
2023년 7월 20일
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)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!