Make informative x-axis labels for long term spectrogram plot
4 次查看(过去 30 天)
显示 更早的评论
I have a spectrogram which spans one month worth of 2 minute recordings. Instead of labelling each two minute recording on the x-axis, I'd like to group the x-axis tick labels by day, so that the data is more readable and informative.
So far, I have converted each serial datenumber in my data to a date, but I am having trouble applying this to the data. I then tried to do this manually but that hasn't worked either.
Any tips much appreciated!
%% Time-domain plot (spectrogram)
figure(1); clf; set(figure(1),'color','w'); hold off;
%produce figure with axes
surf(t,f,A','FaceColor','interp',...
'EdgeColor','none','FaceLighting','phong');
%surf(x,y,Z);
%x corresponds to columns of z (time)
%y corresponds to rows (frequency)
%A is transposed in third input to meet requirements of surf
%Plot uses x and y as coordinates-at x(time) and y(freq), what is A?
axis tight
view(0,90);
set(gca,'tickdir','out','layer','top','fontname',... %change size of axes
'arial','fontsize',14);
%set(gca,'YScale','log'); %set y-axis scale to logarithmic
ylabel('Frequency [ Hz ]','fontsize',14);
c = colorbar; %insert colour bar
colorTitleHandle = get(c,'Title');
titleString = 'PSD [ dB re 1 uPa^2 Hz^-^1 ]';
set(colorTitleHandle ,'String', titleString,'Rotation',270,...
'Position',[60 300 2]); %positions colorbar axis
set(colorTitleHandle, 'fontsize', 14); %change colourbar font size
caxis([40 100]); % sets scale on colour bar
xlabel('Time','fontsize',14);
days=datetime(t,'ConvertFrom','datenum'); %group datenum values into day of month
days=day(days);
xticks(days); %I get an error here which says 'value must be a vector of type single or double whose values increase'
timestamps=[1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;
27;28;29;30;31];
xticks(timestamps)
xticklabels({'01-16','02-16','03-16','04-16','05-16','06-16','07-16','08-16',
'09-16','10-16','11-16','12-16','01-17','02-17','03-17','04-17','05-17',
'06-17','07-17','08-17','09-17','10-17','11-17','12-17'})
xlabel('Date (MM-YY)')
4 个评论
Eric Sofen
2020-10-2
It looks like you found a solution, but FYI, most MATLAB plot types support plotting datetime and duration directly, so instead of overwriting the xticks and the labels, you could do (referring to the variable names in your code above)
surf(days,f,A',...
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!