arrays - plotting missing values with nan -
i have plot looks
hours = [0 1 2 3 4 5 6 12 13 14 15]; y = [0 1 2 nan 3 4 5 6 7 8 9]; figure(1) plot(hours, y, '-o');
as can see, x axis jumps 6 12. instead of having straight line connecting these points, have gap:
hours = [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15]; y = [0 1 2 nan 3 4 5 nan nan nan nan nan 6 7 8 9]; figure(2) plot(hours, y, '-o');
can done in elegant way without having manually insert nans , new 'hours' values?
try -
hours_new = min(hours):max(hours) nan_ind = ~ismember(hours_new,hours) y_new(~nan_ind) = y y_new(nan_ind) = nan
then, plot -
figure(2) plot(hours_new, y_new, '-o');
Comments
Post a Comment