How to plot multiple lines in a same figure using loop?

1 回表示 (過去 30 日間)
Kazi Md. Munim
Kazi Md. Munim 2017 年 10 月 1 日
回答済み: KSSV 2018 年 6 月 22 日
I have a 3d matrix named cluster. I need to plot multiple lines in a same graph. For example if I have 3 clusters in my cluster matrix then I plot them using the line below:
plot(cluster(1:6,1,1),cluster(1:6,2,1),'*',cluster(1:3,1,2),cluster(1:3,2,2),'+',cluster(1:6,1,3),cluster(1:6,2,3),'o');
Graph output:
But the number of cluster may change dynamically. So I need to plot the lines using loop (I guess). How to do that?
  2 件のコメント
Image Analyst
Image Analyst 2017 年 10 月 1 日
Where are the endpoints of the lines? Where do you want the lines to go from, and to? Please attach image with desired result.
per isakson
per isakson 2017 年 10 月 1 日
marker = {'+','o',...};
plot( x(:,1), y(:,1), '*' )
hold on
for jj = 2 : N
plot( x(:,jj), y(:,jj), marker{jj} )
end

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

回答 (1 件)

KSSV
KSSV 2018 年 6 月 22 日
S = rand(1,3) ;
N = 100 ;
E = rand(N,3) ;
figure
hold on
S = repmat(S,N,1) ;
x = [S(:,1) E(:,1)] ;
y = [S(:,2) E(:,2)] ;
z = [S(:,3) E(:,3)] ;
plot3(x',y',z')

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by