Plot time vector in x axis
14 次查看(过去 30 天)
显示 更早的评论
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/158054/image.png)
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.
0 个评论
回答(1 个)
Mischa Kim
2014-3-6
编辑:Mischa Kim
2014-3-6
plot(x,y,'b*');
In this case the marker is a blue star.
2 个评论
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 Center 和 File Exchange 中查找有关 Geographic Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!