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'); 

enter image description here

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'); 

enter image description here

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

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -