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

Automation

Subplots Example in MATLAB

Introduction

Subplots allow us to plot multiple charts on the same figure in a grid. The axes are created in tiled positions. We can create subplots using the subplot command. For example,

subplot(m,n,k)

divides the figure into m x n  grid and k is the kth subplot in the m x n grid.

Let’s create subplots for four sample trigonometric functions like:

  • sin(x)
  • cos(x)
  • tan(x)
  • sin(x)*cos(x)

We will create the four subplots in a 2×2 grid.

MATLAB Script

% Subplots Example - www.TestingDocs.com
% Creates 2x2 subplots

% Create x and y vectors 
x = linspace(-2*pi,2*pi,100);
y1 = sin(x);
y2 = cos(x);
y3 = tan(x);
y4 = sin(x).*cos(x);

% Create 4 Subplots
subplot(2,2,1);
plot(x,y1);
xlabel('x - axis')
ylabel('y - axis')
title('sin(x) plot');
grid on;

subplot(2,2,2);
plot(x,y2);
xlabel('x - axis')
ylabel('y - axis')
title('cos(x) plot');
grid on;

subplot(2,2,3);
plot(x,y3);
xlabel('x - axis')
ylabel('y - axis')
title('tan(x) plot');
grid on;

subplot(2,2,4);
plot(x,y4);
xlabel('x - axis')
ylabel('y - axis')
title('sin(x)*cos(x) plot');
grid on;

Subplots in MATLAB

Related Posts

Emma Tool

Automation /

Code Coverage Tools

Selenium 4 Automation Project

Automation /

Selenium 4 Project Setup on Ubuntu Linux

Testing webpage mobile-friendliness using a tool

Automation /

Testing webpage mobile-friendliness using a tool

Errors Code Testing Development

Automation /

Error Severity Metrics

Automation Environment Setup Verification

Automation /

Automation Environment Setup Verification

‹ Download and Install Octave on Windows 10› Calculator JUnit Tests in Maven Project

Recent Posts

  • MS Access Data Types
  • 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

Go to mobile version