How can I make a plot with the date and time on the x-axis?

2 views (last 30 days)
I have imported some data into Matlap. One of the vectors is date and time (ex 19.12.2013 11:56:22). Matlab have made all date formatted cells into Matlab serial date number format. How can I plot my sound power vector aginst the date-time vector? I would like the date-time on the x-axis(not the date number) and the sound power on the y-axis. I have included a small file with some of my data.

Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 3 Jan 2014
[~,~,v]=xlsread('data.xlsx')
v=v(2:end,:);
x=datenum(v(:,1),'dd/mm/yyyy HH:MM:SS')
y=cell2mat(v(:,2))
[idx,idx]=sortrows([x,y])
plot(x(idx),y(idx))
xticks=get(gca,'Xtick')
set(gca,'xticklabel',datestr(xticks,'dd/mm/yyyy HH:MM:SS'))
  8 Comments
Henriette
Henriette on 6 Jan 2014
I am not so experienced in Matlab, so sometimes I just change things to see if it works, and if I delete ‘dd/mm/yyyy HH:MM:SS’ it gives me a vector with numbers. But the end figure is not correct.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!