Plotting arrays as x and y axis.

I am having two arrays containing about 1000 datas. I have entered the datas using for loop. Now i need to plot the graph with one array as x axis and one array as y axis . How to do it

回答 (1 件)

Mischa Kim
Mischa Kim 2014 年 1 月 12 日
編集済み: Mischa Kim 2014 年 1 月 12 日

4 投票

Are they both 1000x1 (or 1x1000) arrays? If yes, you can simply use
plot(x,y)
where x and y are the two arrays. If no, I need more info on the size of the arrays and on what exactly you would like to plot.

9 件のコメント

ABHISEKH MUKHERJEE
ABHISEKH MUKHERJEE 2014 年 1 月 12 日
yes both the arrays are 1*1000 but when i'm using plot(x,y) then it is plotting only the final value and nothing else
Mischa Kim
Mischa Kim 2014 年 1 月 12 日
編集済み: Mischa Kim 2014 年 1 月 12 日
Could you please post or attach some of the relevant code? You can try
size(x)
to check if x is really an array (matrix) and not just a scalar. Also, don't call the plot-function in the for -loop but after the loop is completed. Something like, for example:
for ii = 1:1000
x(ii) = ii;
y(ii) = sin(0.1*ii);
end
plot(x,y)
ABHISEKH MUKHERJEE
ABHISEKH MUKHERJEE 2014 年 1 月 12 日
yes they are array because when i run them in a loop they give answers of the corresponding term
ABHISEKH MUKHERJEE
ABHISEKH MUKHERJEE 2014 年 1 月 12 日
編集済み: Image Analyst 2014 年 1 月 12 日
I did that way but no graph is plotted in my program
for i=1:1000
y=p1(i)
x=p2(i)
end
plot(x,y)
but no graph is plotted
Mischa Kim
Mischa Kim 2014 年 1 月 12 日
編集済み: Mischa Kim 2014 年 1 月 12 日
OK, that's the problem. You are not generating an array but overwrite the same scalars. Assuming that p1 and p2 are arrays and defined, try:
for i = 1:1000
y(i) = p1(i);
x(i) = p2(i);
end
plot(x,y)
But then you can simply use plot(p2,p1) since they are equal to x and y.
Image Analyst
Image Analyst 2014 年 1 月 12 日
ABHISEKH, this is something you could have found out very easily by looking at the values of x and y right before you called plot. So this tells me you are not familiar with debugging and you should look at Doug's great video tutorial link: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/ It will help you a lot and make it so much faster for you to solve issues like this.
Sophia Christel
Sophia Christel 2017 年 4 月 18 日
I have a similar problem. I have two arrays x and y (both in the 1x991 Double format) which I would like to plot against each other, but simply calling plot(x,y) doesn't do anything. I have:
x=0.1:0.01:10;
n=length(x);
y=zeros(1,n);
for k=1:n;
y(k)=func(x(k),2,4);
end
plot(x,y)
I have checked both arrays and I don't see anything wrong with them.
Dhrumil
Dhrumil 2022 年 11 月 21 日
Graph an array of size 10x1 with random values plot the line of the array change the 3 element of the array with 10 and line color changed array with line doing red and the same plot
Dhrumil
Dhrumil 2022 年 11 月 21 日
Graph an array of size 10x1 with random values plot the line of the array change the 3 element of the array with 10 and line color changed array with line doing red and the same plot

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

カテゴリ

ヘルプ センター および File ExchangeLine Plots についてさらに検索

タグ

質問済み:

2014 年 1 月 12 日

コメント済み:

2022 年 11 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by