How to link markers with lines in for loop

2 ビュー (過去 30 日間)
Mohammed Sadeq
Mohammed Sadeq 2016 年 1 月 14 日
コメント済み: harjeet singh 2016 年 1 月 16 日
When I plot a graph using for loop with Matlab 2015a as below:
The plot look like this:
I want to connect each 'n' with line as follows:
How to do that?
Thanks..

採用された回答

harjeet singh
harjeet singh 2016 年 1 月 14 日
try to use this code
clear all
close all
clc
X=randint(5,100,[1 1000]);
Y=randint(1,100,[1 1000]);
for n=1:100
x=[];
y=[];
for k=1:5
x=[x X(k,n)];
y=[y Y(1,n)];
end
figure(1)
plot(y,x,'-o')
hold on
drawnow
end
  4 件のコメント
harjeet singh
harjeet singh 2016 年 1 月 16 日
thanks @mohammed for accepting answer.

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

その他の回答 (1 件)

Stephen23
Stephen23 2016 年 1 月 14 日
編集済み: Stephen23 2016 年 1 月 14 日
Solution: learn to program MATLAB code without using loops everywhere.
Although beginners think that loops are great for solving all of their problems, in fact MATLAB works best when you learn to perform your operations on all of arrays at once, in particular by writing vectorized code. So you can just pass the plot function your data matrices, and it will plot the columns of that matrix. This is clearly explained in the plot documentation.
>> X = [0.1,0.1,0.2,0.3,0.5;1.1,1.1,1.1,1.2,1.4]';
>> Y = [5,4,3,2,1;4,3,2,1,0]';
>> plot(X,Y,'-o')
>> grid on
>> legend({'one','two'})
See, no loops!
  3 件のコメント
Mohammed Sadeq
Mohammed Sadeq 2016 年 1 月 15 日
@Stephen, I believe you didn't understand my problem and your last comment prove it. Anyway, thanks for trying..

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

カテゴリ

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