0
votes

I want to draw a line in matlab. My scenario is like x=[-400:400] and 'y' should be of the same length but an irregular slope continuous line and finally I want to use plot command for plotting, say plot(x,y). Can anybody suggest how to do it.

Thanks

1
This isn't clear; if you know that you need to use plot(x,y), then what is the problem? - Oliver Charlesworth
It seems you've already answered your question. - chaohuang
I have to plot irregular line how will I choose the value of y - Justin Oommen
for x=-400 to -300 , y should be 150; ; for x= -300 to -200 , y should be from 150 to -200;; for x= -200 to 300, y should be from -200 to 200;; so on ..and I want to plot in one graph using plot(x,y) - Justin Oommen
@JustinOommen: That would be just plot([-400 -300 -200 300], [150 150 -200 200]) - H.Muster

1 Answers

1
votes

Assume you want to plot in steps of 1, then you have:

x1=-400:-300;
x2=-300:-200;
x3=-200:300;
x=[x1 x2 x3];

And then for y you will have:

y1=ones(1,length(x1));
y2=(-200-150)/(-200+300) (x2+300) + 150;
y3=(200+200)/(300+200) (x3+200) - 200;
y=[y1 y2 y3]

And then :

plot(x,y)