在两个序列的匹配部分之间绘制线条

时间:2014-01-07 12:47:25

标签: matlab plot line time-series octave

我有两个不同的序列:seq1seq2

seq1 = {1,2,3,4}; 
seq2 = {3,4,6,7,8}; 
matchedIndexes ={{4,5},{4,4},{4,3},{4,2},{3,1},{2,1},{1,1}}; 

我想在相同的情节中使用matlab绘制seq1seq2以及匹配部分之间的线条。

我尝试了以下内容,

plot(seq1);
hold on;
plot(seq2);
//How to draw lines between matched parts?

2 个答案:

答案 0 :(得分:3)

也许这就是你想要的(在Matlab中):

seq1 = {1,2,3,4}; 
seq2 = {3,4,6,7,8}; 
matchedIndexes ={{4,5},{4,4},{4,3},{4,2},{3,1},{2,1},{1,1}};

seq1 = cell2mat(seq1); %// convert to vector
seq2 = cell2mat(seq2); %// convert to vector
plot(seq1,1,'ro')
hold on
plot(seq2,2,'ro')
for k = 1:numel(matchedIndexes)
    plot([seq1(matchedIndexes{k}{1}) seq2(matchedIndexes{k}{2})], [1 2])
end
axis([min([seq1 seq2])-1 max([seq1 seq2])+1 0.5 2.5])

enter image description here

答案 1 :(得分:3)

使用@Luis Mendo的代码:

seq1 = {1,2,3,4}; 
seq2 = {3,4,6,7,8}; 
matchedIndexes ={{4,5},{4,4},{4,3},{4,2},{3,1},{2,1},{1,1}};

seq1 = cell2mat(seq1); %// convert to vector
seq2 = cell2mat(seq2); %// convert to vector
plot(seq1)
hold on
plot(seq2)

for k = 1:numel(matchedIndexes)
    plot([matchedIndexes{k}{1} matchedIndexes{k}{2}], [seq1(matchedIndexes{k}{1}) seq2(matchedIndexes{k}{2})], 'r')
end

输出结果为:

enter image description here