TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Octave

Octave plot command

Overview

In this tutorial, we will learn about the Octave plot command with examples. The plot command is the basic command to generate 2D plot in Octave.

Syntax

The basic syntax for the command is:

plot(x,y)

Optionally, we can provide many options to the command:

plot(x,y,[options])

x and y are coordinates scalars or vectors. When the x and y are scalars the command plots a single point. If x and y are vectors the command plots all the points joining them with straight lines in a figure window.

The x, y vectors must be of the same length. An error will occur if the vectors are not the same length.

Example

% Example plot command demo
% Octave Tutorials - www.TestingDocs.com

clear all; 
clf; 

% Generate x vector
x = linspace(0,4*pi,100);

% Generate y vector
y = cos(x);

% 2D-plot 
plot(x,y);

% Labels and Title for the graph
xlabel('x-axis');
ylabel('y-axis');
title('Sample Octave Plot cos(x)');

Octave Plot Command

clear all;

This command clears all the existing variables from the workspace. The practice of clearing the workspace at the start is highly recommended. It also frees up the system memory.

clf;

This command clears the current figure window.

linspace

linspace is a built-in function. The function returns a row vector with N linearly spaced elements between the START and the END.

linspace (START, END, N)

xlabel(‘string’);

The xlabel command will display the label along the x-axis in the figure.

ylabel(‘string’);

The ylabel command will display the label along the y-axis in the figure.

title(‘string’);

The title command will display the title for the figure.

Screenshot

Octave Plot Screenshot

plot

The plot command is used to create the plot. The default style of plotting in Octave is a thin blue line to connect the points. To change the appearance of the plot, we can add another argument to the plot command.

For example, to change the plot to appear as a thin red line with x marks:

plot(x,y,’r-x’)

red line plot Octave

hold on;

This command will allow us to plot multiple plots within the same figure window.

grid on;

The grid command will make a grid appear in the figure window.

 

grid on Octave plot

—

Octave Tutorials

GNU Octave Tutorials on this website can be found at:

https://www.testingdocs.com/octave-tutorial/

For more information on Octave, visit the official website:

https://www.gnu.org/software/octave/index

Related Posts

Octave Package List

Octave /

Install Octave Packages on Linux

Octave /

Octave User defined Function Example

octave command line linux

Octave /

Octave Command line on Ubuntu

Hello World in Octave

Octave /

Hello World in Octave

Octave /

Octave plot example of function y=x^2

‹ Octave Functions› Octave Built-in functions

Recent Posts

  • Update draw.io on Windows
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com