Plot time vector in x axis

14 Ansichten (letzte 30 Tage)
Chani
Chani am 6 Mär. 2014
Kommentiert: Mischa Kim am 6 Mär. 2014
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.

Antworten (1)

Mischa Kim
Mischa Kim am 6 Mär. 2014
Bearbeitet: Mischa Kim am 6 Mär. 2014
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 Kommentare
Chani
Chani am 6 Mär. 2014
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 am 6 Mär. 2014
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Geographic Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by