Customize the x-axis of hht plot

3 次查看(过去 30 天)
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');
.

更多回答(0 个)

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by