Why does plot function just draw points instead of line

Hi, I have a problem with plot function. It only draw points instead of line. LineWidth and putting '-' doesn't work.
% for j=2:stc
for i=2:n-1
M(j,i)=K1*(M(j-1,i+1)-2*M(j-1,i)+M(j-1,i-1))+M(j-1,i);
plot(j,M(j,i),'-','LineWidth',3)
hold on
end
M(j,n)=-K3*(M(j,n-1)-To)+M(j,n-2)
end
With this code I get plot like this:
Does anyone know what is wrong with code and how to get solid line back to plot? Thanks

1 件のコメント

Christine Tobler
Christine Tobler 2015 年 12 月 31 日
I don't know what's happening. Does this still happen if you restart MATLAB and directly call
plot([1 2], [1 2], '-')

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

 採用された回答

Walter Roberson
Walter Roberson 2015 年 12 月 31 日

1 投票

This is expected. One line is generated for each column of y values (or just one line if y is a row vector) for each call to plot(). You are making multiple calls to plot(), giving a single coordinate each time, so each one is generating a different line.
If you want to join together multiple points in a single line then all of the values must be passed to the plot() call. In practical terms this means you should move your plot() call to after the "for i" loop and plot(j, M(i,:)) . Or better yet move it to after the "for j" loop and plot(2:stc, M(2:end,:))

1 件のコメント

martian
martian 2016 年 1 月 9 日
Thanks for your answer. I moved plot after both loops and it works now :)

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

その他の回答 (0 件)

カテゴリ

質問済み:

2015 年 12 月 28 日

コメント済み:

2016 年 1 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by