Customize the x-axis of hht plot

조회 수: 7 (최근 30일)
Sujata Dhar
Sujata Dhar 2024년 1월 26일
댓글: Star Strider 2024년 1월 26일
For the following hht plot, I want to customize datetime values for 501 data points in x-axis instead of default time values. The datetime values should start from 01-01-1995.
t = 0:0.01:5;
signal = sin(2*pi*2*t) + sin(2*pi*5*t) + randn(size(t));
imf = emd(signal);
% Plot HHT spectrum
hht(imf, 1/mean(diff(t)), 'FrequencyLimits', [0 5]);
% Customize plot labels and title
xlabel('Time');
ylabel('Frequency (Hz)');
title('Hilbert-Huang Transform (HHT) Spectrum');

채택된 답변

Star Strider
Star Strider 2024년 1월 26일
Putting 501 datetime x-ticks would be impossible to read, at least with this example. This creates all of them, nowever only uses 24 for obvious reasons.
Make appropriate changes to use the ones you want —
t = 0:0.01:5;
signal = sin(2*pi*2*t) + sin(2*pi*5*t) + randn(size(t));
imf = emd(signal);
% Plot HHT spectrum
hht(imf, 1/mean(diff(t)), 'FrequencyLimits', [0 5]);
Ax = gca;
xt = Ax.XTick;
N = 501;
xtime = linspace(min(xt), max(xt), N);
DT = datetime(1995,1,1) + years(xtime);
DT.Format = 'dd-MMM-yyyy';
xtnew = linspace(min(xt), max(xt), numel(xt)*4);
xtlnew = linspace(min(DT), max(DT), numel(xt)*4);
Ax.XTick = xtnew;
Ax.XTickLabel = compose('%s',xtlnew);
% Customize plot labels and title
xlabel('Time');
ylabel('Frequency (Hz)');
title('Hilbert-Huang Transform (HHT) Spectrum');
.
  댓글 수: 2
Sujata Dhar
Sujata Dhar 2024년 1월 26일
Thank you.
Star Strider
Star Strider 2024년 1월 26일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Hilbert and Walsh-Hadamard Transforms에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by