Equation of a straight line, how to create an equation with two matrices?

I am a newbie in Matlab I know it will sound silly to most of you guys but I could not solve an example about creating a straight line with the:
x=10, y=1 and x will decrease up to 0, y will increase up to 10. I tried to do something like this:
A=[10,9,8,7,6,5,4,3,2,1];
x=A; B=1:10;
y=B;
for n=1:10 m=y(n)/x(n); plot(x,m*x-(x-x(n))) xlim([0 10]) ylim([0 10])
pause(2)
end
I used pause to see every change in the graph yet the output is something quite different from what I was expecting.
Any suggestions? Again I am a newbie sorry if it is too easy :)
Waiting for answers...Thanks Okan..

 Accepted Answer

Are you trying to draw a line from (10,1) to (0,10)?
line([10,0],[1 10])
Or you mean this:
x=zeros(2,10);
y=zeros(2,10);
x(1,:)=10:-1:1;
y(2,:)=1:10;
line(x,y)

4 Comments

No. I am trying to draw from (10,0) to (0,1)
(9,0) to (0,2)
(9.0) to (0.3) and so on..
Thank you so much mate. That's the thing what I was trying to get thanks again. I think I have to learn the matrix manipulation before I continue to other parts. Best Regards

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!