Plotting use datenum

Hello, I want to make a Matlab plot with the months of the year on the x-axis. I am trying to plot a total of 17520 readings (48 per day) on the y-axis and then show the months on the x-axis. The problem with the code I am using now is that the vectors are different lengths (b is 12 and a is 17520).
Here is my code:
function [y] = doc_concentration
a = xlsread ('DOC_Conc_2007-2011.xlsx',1,'A3:A17522');
startDate = datenum('01-01-2007');
endDate = datenum('12-31-2007');
b = linspace(startDate,endDate,12);
length(a)
length (b)
plot (b,a)
set(gca,'XTick',g)
datetick('x','mmm','keepticks')
end
Can anyone help? Thanks in advance.
Maeve

댓글 수: 1

Jan
Jan 2012년 1월 26일
Please format your code properly using the "{} code" button. I've done this for you this time.

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

답변 (1개)

Jan
Jan 2012년 1월 26일

0 개 추천

Why do you use 12 bins, if you need 17520? What about:
b = linspace(startDate, endDate, 17530)

댓글 수: 4

Maeve  Ryan
Maeve Ryan 2012년 1월 26일
I tried this now and it's plotting it but only the months Jan, April, July and October along with Jan of the next year which I don't want.
Here's what I tried
function [y] = doc_concentration
a = xlsread ('DOC_Conc_2007-2011.xlsx',1,'A3:A17522');
startDate = datenum('01-01-2007');
endDate = datenum('12-31-2007');
b = linspace(startDate,endDate,17520);
plot (b,a)
set(gca,'XTick',b)
datetick('x','mmm','keeplimits')
end
Any ideas how I can get every month to appear on the x-axis and leaving out January of the next year?
Thanks for your help
Jan
Jan 2012년 1월 26일
Perhaps this helps: set(gca, 'XLim', [startDate, endDate])
Another idea is not to set the XTick values manually, but let DATETICK decide.
Maeve  Ryan
Maeve Ryan 2012년 1월 26일
ok using set (gca,'XLIM',[startDate,endDate}] removed the January label from the next year which helps.
I still cannot figure out how to get every month to appear on the x-axis instead of just every fourth month which is happening now
Jan
Jan 2012년 1월 26일
You can set the ticks explicitely instead of using "set(gca, 'YTick', B'; datetick('x', 'mmm');".

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

카테고리

도움말 센터File Exchange에서 Dates and Time에 대해 자세히 알아보기

질문:

2012년 1월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by