Line plotting

5 ビュー (過去 30 日間)
Andy
Andy 2011 年 11 月 3 日
for yy = 1:length(overlap_peaks2)
x=overlap_peaks2(yy);
y=1:200000:1000000;
hold on;
plot(overlap_peaks2(yy),y, '-r')
end
length(overlap_peaks2) is just equal to 1
my question is why is it when i plot it, it shows up as seperate dots, how do i make it connect into a line? i am just tryign to plot x=589

採用された回答

Walter Roberson
Walter Roberson 2011 年 11 月 3 日
for yy = 1:length(overlap_peaks2)
x=overlap_peaks2(yy);
y=1:200000:1000000;
hold on;
plot(repmat(x,1,length(y)),y, '-r')
end
By the way, you should also consider
for yy = 1:length(overlap_peaks2)
x=overlap_peaks2(yy);
hold on;
plot([x x],[1 1000000], '-r')
end

その他の回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2011 年 11 月 3 日
If "length(overlap_peaks2) is just equal to 1", then in your code, yy will be 1 and the loop runs once. What is the length of overlap_peaks2(yy)? If it's a scalar, you are just going to get 5 dots.
Check your code again.
  2 件のコメント
Andy
Andy 2011 年 11 月 3 日
in this case overlap_peaks2 is just size of 1, but in some other cases it will be longer. How do i connect those dots with a line?
Fangjun Jiang
Fangjun Jiang 2011 年 11 月 3 日
Usually x and y are two vectors with the same size in plot(x,y), such as plot(1:10,sin(1:10)). plot(1,1:10,'-r') or plot(1:10,1,'-r') still generates a plot but only shows 10 points. Even if you can use plot(repmat(1,1,10),1:10,'-r') to make it draw the line, I am not sure what the line means to you.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by