フィルターのクリア

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 Center および File ExchangeGrid 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