필터 지우기
필터 지우기

Plot time vector in x axis

조회 수: 8 (최근 30일)
Chani
Chani 2014년 3월 6일
댓글: Mischa Kim 2014년 3월 6일
I have a time vector: time = 62949,62950,62951,62952,62953,62954... Where the first one/two digits represent the hour, the third/fourth digits represent the minute and the last two digits represent the seconds. Every second I have a new measurement point.
The problem is, when I plot my data, matlab interpolates between the minute and the hour transition, e.g. from 65959 to 70000. I tried to use datenum and datetick, but that did not work well. See the picture of the plot.
timeStr = arrayfun(@num2str, time, 'UniformOutput', false);
time = datenum(timeOUTStr,'hhmmss');
plot(time(indexOUT1:indexOUT2), GPS_Data_Raw{5,2}(indexOUT1:indexOUT2,i),'Color',[colors(j,:)],'DisplayName',name,'LineWidth',1.5);
xlim([timeOUT(indexOUT1)-100 timeOUT(indexOUT2)+100]);
ylim([0 60]);
set(gca,'XTick',timeOUT(indexOUT1)-100:1:timeOUT(indexOUT2)+100);
set(gca, 'XTickLabel', num2str(get(gca,'XTick')','%d'))
set(gca,'YTick',0:5:60);
datetick('x', 'HH:MM:SS');
This code leads to this:
All I want is that matlab only plots the data in my vectors and does not interpolate between "missing" data. Maybe I did something wrong while using datenum and datetick or there is another possibility forcing the plot to show only the data given in the x vector.
Thank you in advance for help.

답변 (1개)

Mischa Kim
Mischa Kim 2014년 3월 6일
편집: Mischa Kim 2014년 3월 6일
Chani, you can simply just plot markers, e.g., note the 'b*' in
plot(x,y,'b*');
In this case the marker is a blue star.
  댓글 수: 2
Chani
Chani 2014년 3월 6일
I figured out how it works with datenum, I extracted the hour, minutes and seconds from my time vector and after that used the following code:
time = datenum(repmat(2014,size(hourOUT,1),1),repmat(03,size(hourOUT,1),1),repmat(01,size(hourOUT,1),1),hourOUT,minuteOUT,secondOUT);
plot(time(indexOUT1:indexOUT2), GPS_Data_Raw{5,2}(indexOUT1:indexOUT2,i),'Color',[colors(j,:)],'DisplayName',name,'LineWidth',1.5); ylim([0 60]); grid minor; set(gca,'YTick',0:5:60); datetick('x', 'HH:MM:SS');
Now it looks like this:
The next question is, how I can increase the x Axis resolution in such a way that i see every single minute or so.
Any ideas? :)
Mischa Kim
Mischa Kim 2014년 3월 6일
You need to set axis ticks and tick labels. Check out
t = 0:100;
y = rand(1,length(t)); % just some made-up data
t_int = 10; % tick intervals
tt = t(rem(t,t_int)==0); % find tick locations
ttlab = num2cell(tt); % and generate tick labels
plot(t,y)
set(gca,'XTick', tt, 'XTickLabel', ttlab)
and change t_int. For your problem t_int would be determined by your minute-spacing requirement.

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

카테고리

Help CenterFile Exchange에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by