How to change interval unit of x axis

조회 수: 3 (최근 30일)
Sehoon Chang
Sehoon Chang 2020년 1월 13일
편집: Meg Noah 2020년 1월 14일
Hi everyone,
I am trying to figure out how to adjust the graph by changing the interval of my X axis.
I made a timetable and both X and Y values have 17300 arrays, X-value being the time interval in 15 minutes of half year.
The graph came out well. However, i wish to adjust the X-axis into hourly interval.
Is there code that adjusts a graph according to a defined inteval of X-axis?
Using the graph as an exmaple that i have made:
it can be seen that the X-axis value goes up to 18000 (15-Min Interval measurements of a half year).
I wish to change X-axis go upto 4380 (hourly Interval measurement of a half year).
I appreciate for your advice and help.
JC
  댓글 수: 2
Meg Noah
Meg Noah 2020년 1월 13일
did you try
xlim([minX maxX]);
?
Sehoon Chang
Sehoon Chang 2020년 1월 13일
Thank you Meg Noah for your comment.
I have tried both
1) set(gca,'xtick',....,'xticklabel',....)
2) xlim([minX maxX]);
However, both codes only restrict or changes the X-Axis Interval, not chaging the graph line.

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

채택된 답변

Meg Noah
Meg Noah 2020년 1월 14일
편집: Meg Noah 2020년 1월 14일
Here's one way
You can do shape downsampling - reshape then sum the lines. I made some data by digitizing yoour plot. It's attached. But use your data for the real plot of course!
load('Halbjahresdauerlinie_15min.mat')
npts = length(Halbjahresdauerlinie_15min.Heizstunden);
if (~mod(npts,4) == 0)
error('unable to downsample because array length needs to be a factor of 4');
end
Leistung = sum(reshape(Halbjahresdauerlinie_15min.Leistung,4,npts/4))';
Leistung = Leistung/4;
Heizstunden = Halbjahresdauerlinie_15min.Heizstunden(1:4:end)/4';
Halbjahresdauerlinie_Daily = table(Heizstunden,Leistung);
figure();
plot(Halbjahresdauerlinie_Daily.Heizstunden,Halbjahresdauerlinie_Daily.Leistung);
xlabel('Heizstunden per day');
ylabel('Leistung in kW');
title('Halbjahresdauerlinie')
You can just down sample the time axis which are 15-min intervals, or you can do mean(reshape(Halbjahresdauerlinie_15min.Heizstunden, 4, npts/4); It depends upon how you want to annotate the time axis for each plot - from the half day or from the start of day...
untitled.png

추가 답변 (1개)

Eric Sofen
Eric Sofen 2020년 1월 13일
If X is a duration array (X = minutes(0:15:262800)), you plot datetimes or durations directly, and changing the Format property of the duration will change how it displays.
compare
plot(X,Y)
to
X.Format = 'h';
plot(X,Y)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by