我有一系列我希望绘制的点,但如果点相距太远,则可能会在结果曲线处断开。
所以在1D CASE中:
1 2 3 7 9 11 12 16 18 19
就像:
1-2-3 7-9-11-12 16-18-19
or : seq1 seq2 seq3
我想将我的序列绘制为未连接的离散部分seq1
seq2
和seq3
。
我不太清楚如何去做这个
答案 0 :(得分:1)
将下面的代码段添加到您的问题解决方案中。我尽可能在代码中解释,但如果有什么不清楚,请不要犹豫。
% constants, thresold defintion
T = 4;
% your data
a = [1 2 3 7 9 11 12 16 18 19 24 25 26 28 35 37 38 39];
% preparing the x-axis
x = 1:length(a);
% Getting the differences between the values
d = diff(a);
% find the suggested "jumps/gaps", greater/equal than the threshold
ind = find(d>=T);
figure;
hold on;
% Plotting the first part of a
y = nan*ones(1,length(a));
y(1:ind(1)) = a(1:ind(1));
plot(x,y);
% Plotting all parts in between: go through all found gaps
% and plot the corresponding values of "a" between them
for j=2:length(ind)
y = nan*ones(1,length(a));
y(ind(j-1)+1:ind(j)) = a(ind(j-1)+1:ind(j));
plot(x,y);
end;
% Plotting the last part of a
y = nan*ones(1,length(a));
y(ind(j)+1:end) = a(ind(j)+1:end);
plot(x,y);