将曲线绘制为较小的部分,matlab

plot a curve as smaller parts, matlab

我有一系列要绘制的点,但如果这些点相距太远,则生成的曲线可能会在某些地方断开。

所以在 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 seq2seq3,它们没有连接。

我不太确定该怎么做

搜索下面的代码片段以解决您的问题。我尝试在代码中尽可能多地解释,但如果有任何不清楚的地方,请不要犹豫。

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