我有两个不同的序列:seq1
和seq2
。
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绘制seq1
和seq2
以及匹配部分之间的线条。
我尝试了以下内容,
plot(seq1);
hold on;
plot(seq2);
//How to draw lines between matched parts?
答案 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])
答案 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
输出结果为: