SlideShare a Scribd company logo
1 of 8
How to Plot a Straight Line in
Matlab
This also works in GNU-Octave,
FreeMat, Scilab and Scicoslab
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
For example, plot this line:
(3, 4)
(-1, 2)
(3, 4)
(-1, 2)
% create your x and y-arrays
x = [-1 3];
y = [2 4];
% just plot the line:
plot(x, y)
So this short code:
x = [-1 3];
y = [2 4];
plot(x, y)
produces this plot:
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
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
For alternative codes, examples and
details, visit:
matrixlab-examples.com/horizontal-lines.html

More Related Content

Viewers also liked (7)

2D Plot Matlab
2D Plot Matlab2D Plot Matlab
2D Plot Matlab
 
Towers Hanoi Algorithm
Towers Hanoi AlgorithmTowers Hanoi Algorithm
Towers Hanoi Algorithm
 
Xcos scilab
Xcos scilabXcos scilab
Xcos scilab
 
Equations of Straight Lines
Equations of Straight LinesEquations of Straight Lines
Equations of Straight Lines
 
Read electric meter
Read electric meterRead electric meter
Read electric meter
 
Line Graph Presentation
Line Graph Presentation Line Graph Presentation
Line Graph Presentation
 
Gr10 step function ppt
Gr10 step function pptGr10 step function ppt
Gr10 step function ppt
 

Recently uploaded

Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 

Recently uploaded (20)

Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 

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
  • 3. For example, plot this line: (3, 4) (-1, 2)
  • 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