How do I make gaps in missing data plot lines?
27 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Miriam Daughtery
am 7 Okt. 2019
Beantwortet: Miriam Daughtery
am 10 Okt. 2019
I'm relatively new to matlab, so I don't know if this is an easy question to answer.
How do I make gaps in my plot line where data is missing? Thank you
0 Kommentare
Akzeptierte Antwort
Star Strider
am 7 Okt. 2019
It would be easier with your data.
One option is to fill the missing entries with NaN values:
x = [1:10 15:20]; % Create Vector (11:14 Missing)
y = [rand(1,10) rand(1,6)]; % Create Vector (11:14 Missing)
figure
plot(x, y)
grid
dx = (diff([0 x])); % Differences Between Coinsecutive Elements
xnan = nan(1, dx(dx > 1)-1); % ‘NaN’ Vector (Fill Missing Elements)
dxi = find(dx > 1); % First Index Of Missing Elements
xc = [x(1:dxi-1) xnan x(dxi:dxi+numel(xnan)+1)]; % Replace Missing Elements With ‘xnan’ Vector
yc = [y(1:dxi-1) xnan y(dxi:dxi+numel(xnan)+1)]; % Replace Missing Elements With ‘xnan’ Vector
figure
plot(xc, yc)
grid
Experiment with your data to get the result you want.
0 Kommentare
Weitere Antworten (2)
Daniel M
am 7 Okt. 2019
help plot
You are the one telling Matlab to plot a line between your data points. Try
plot(x,y,'c.')
Siehe auch
Kategorien
Mehr zu Graphics Object Properties finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!