How do I make gaps in missing data plot lines?

22 ビュー (過去 30 日間)
Miriam Daughtery
Miriam Daughtery 2019 年 10 月 7 日
回答済み: Miriam Daughtery 2019 年 10 月 10 日
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

採用された回答

Star Strider
Star Strider 2019 年 10 月 7 日
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.

その他の回答 (2 件)

Daniel M
Daniel M 2019 年 10 月 7 日
help plot
You are the one telling Matlab to plot a line between your data points. Try
plot(x,y,'c.')
  1 件のコメント
Miriam Daughtery
Miriam Daughtery 2019 年 10 月 7 日
I want to keep the line but just leave a gap between the points where data us missing
this is my script:
d = dir('*.txt');
t = [];
T = [];
S = [];
O = [];
for I= 1 : length(d)
[tmpt,tmpT,tmpS,tmpO]=process_datafile(d(I).name);
t = [t tmpt];
T = [T tmpT];
S = [S tmpS];
O = [O tmpO];
end
subplot(3,1,1)
plot(t,T, '.k-', 'MarkerEdgeColor','r', 'MarkerFaceColor','r', 'MarkerSize',9)
x=-100:0.5:100;
y=x.^5-x.^2;
xlabel ('Day Of Year')
ylabel ('SST (^oC)')
grid on
legend('2013','2012')
hold on
title ('L4 daily mean sea surface temperature, salinity and O_2 levels 2012-2013')
subplot(3,1,2)
plot(t,S, '.k-', 'MarkerEdgeColor','r', 'MarkerFaceColor','r', 'MarkerSize',9)
xlabel ('Day Of Year')
ylabel ('Salinity (ppt)')
grid on
legend('2013','2012')
hold on
subplot(3,1,3)
plot(t,O, '.k-', 'MarkerEdgeColor','r', 'MarkerFaceColor','r', 'MarkerSize',9);
xlabel ('Day Of Year')
ylabel ('O_2 levels (%)')
grid on
legend('2013','2012')
hold on

サインインしてコメントする。


Miriam Daughtery
Miriam Daughtery 2019 年 10 月 10 日
Thanks everyone

カテゴリ

Help Center および File ExchangeGraphics Object Properties についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by