Customize the x-axis of hht plot

2 Ansichten (letzte 30 Tage)
Sujata Dhar
Sujata Dhar am 26 Jan. 2024
Kommentiert: Star Strider am 26 Jan. 2024
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');

Akzeptierte Antwort

Star Strider
Star Strider am 26 Jan. 2024
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 Kommentare
Sujata Dhar
Sujata Dhar am 26 Jan. 2024
Thank you.
Star Strider
Star Strider am 26 Jan. 2024
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Polynomials finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by