How to plot a straight line in Matlab. The same code works in GNU-Octave, FreeMat, Scilab and Scicoslab.
You need at least two points and the built-in function plot.
More info at: http://matrixlab-examples.com/horizontal-lines.html
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Plot a straight line in Matlab
1. How to Plot a Straight Line in
Matlab
This also works in GNU-Octave,
FreeMat, Scilab and Scicoslab
2. You can plot a straight line just as you would plot
any other function in Matlab.
The basic use of the built-in function plot is:
plot(x, y)
where
x = array of x-values
y = array of y-values
4. (3, 4)
(-1, 2)
% create your x and y-arrays
x = [-1 3];
y = [2 4];
% just plot the line:
plot(x, y)
5. So this short code:
x = [-1 3];
y = [2 4];
plot(x, y)
produces this plot:
6. You can plot more that one line by using the hold on
command once (after the first plot)…
plot([-1 3], [2 4])
hold on
plot([1 1], [5 2])
produces this plot
7. You can have different colors and widths
plot([-1 3], [2 4], ‘r’, ‘Linewidth’, 2)
hold on
plot([1 1], [5 2], ‘k’, ‘Linewidth’, 3)
produces this plot
8. For alternative codes, examples and
details, visit:
matrixlab-examples.com/horizontal-lines.html