WaterFraction=[0.705 0.047 -0.15 -0.046 0.18 -0.070 -0.089 -0.0815 -0.0731 -0.08 ...
-0.43 -0.537 -0.543 -0.62 -0.548 -0.55 -0.33 -0.112 0.10 0.0590 ]
Radius=[ -1.25 -0.811 -0.448 -0.320 -0.384 -0.0923 0.168 0.1039 0.039 0.276 ...
-0.127 -0.137 -0.1088 -0.080 0.0220 0.049 2.34 4.58 6.84 -8.0]
当我按时间向量绘制数据向量时,两者的大小当然相同,有时会发生这种情况,这在视觉上是令人不快的。
我指的是从最后回到起源的直线。 最好, 阿比德
答案 0 :(得分:3)
根据您的情况,您有几种选择。您可以对数据进行排序以防止不连续,也可以在X和Y向量中插入一些NaN
。
要排序:
[xSorted, ixsSort] = sort(x);
ySorted = y(ixSort);
plot(xSorted, ySorted);
要添加nans,您需要做一些额外的工作来确定中断的位置,然后插入NaN。例如,要在第10个条目之后打破该行
xBroken = [x(1:10) nan x(11:end)];
yBroken = [y(1:10) nan y(11:end)];
plot(xBroken, yBroken);
编辑:请参阅下面的示例代码以获取更全面的示例。
当然,作为一个简单的备份,只需做散点图而不是线图:
plot(x, y, '.');
以下方法2的一些示例代码:
%Some sample data
x = [1:10 2.1:11 3.2:12];
y = randn(size(x));
%Define where breaks are needed (and associated boundaries)
ixsBreaksNeeded = find(diff(x)<0);
ixsSegmentBoundaries = [0 ixsBreaksNeeded length(x)]; %This makes the iterations a lot easier
%Predefine some nan vectors to move data into
xBroken = nan(1, length(x) + length(ixsBreaksNeeded));
yBroken = nan(1, length(x) + length(ixsBreaksNeeded));
%Move data segments into nan vectors, leaving gaps between segments
ixOffset = 0;
for ix = 2:length(ixsSegmentBoundaries)
ixsOriginal = (ixsSegmentBoundaries(ix-1)+1):ixsSegmentBoundaries(ix);
xBroken(ixsOriginal + (ixOffset)) = x(ixsOriginal);
yBroken(ixsOriginal + (ixOffset)) = y(ixsOriginal);
ixOffset = ixOffset+1;
end
%Plot to demonstrate
subplot(211)
plot(x,y);
subplot(212)
plot(xBroken, yBroken)