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

    Matlab

    MATLAB 2D Plot command

    Introduction

    The basic plot function in MATLAB is the plot linear plot command. The simple plot command takes two vectors X and Y and plots them in 2D space.

    plot(X,Y)

    The plot command can plot in color and with different symbols.

    plot command

    Let’s issue the plot command from the Command Window prompt. Create two vectors for the plot command.

    >> x = linspace(-pi,pi,100);
    >> y = tan(sin(x)) - sin(tan(x));
    >> plot(x,y)

    Screenshot

    plot command MATALB

     

    linspace creates a linearly spaced vector. For example,

    linspace(low,high,N) created N points between low and high.

    Sample Script

    Lets write a simple script to add title , labels to the graph.

    % Sample MATLAB Script to plot a function
    % MATLAB Tutorials - www.TestingDocs.com
    
    x = linspace(-pi,pi,100); % 100 linearly spaced points within [-pi,pi]
    y = tan(sin(x)) - sin(tan(x)); % Plot function
    
    plot(x,y);
    xlabel('x-axis');
    ylabel('y-axis');
    title('MATLAB 2D Plot Demo - www.TestingDocs.com');

     

    Run the script.

    Notice that the graph now has a title and x,y axis labels.

     

    plot labels and title

     

    Adding markers to the plot command.

    plot(x,y,’:bs’,’LineWidth’,1.5,…
    ‘MarkerEdgeColor’,’g’,…
    ‘MarkerFaceColor’,’k’,…
    ‘MarkerSize’,6)

     

    Plot Markers MATLAB

     

    MATLAB Tutorials on this website can be found here:

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

    To try MATLAB Software or to learn more about MATLAB,

    MATLAB official website:

    https://www.mathworks.com

    Related Posts

    Matlab /

    Taylor series expansion MATLAB Example

    MATLAB For Loop Script

    Matlab /

    For Loop Example in MATLAB

    Pie Chart Demo Matlab

    Matlab /

    Pie Chart Example using MATLAB

    New Function

    Matlab /

    Functions in MATLAB

    MATLAB Command Window

    Matlab /

    MATLAB Command Window

    ‹ Pie Chart Example using MATLAB› For Loop Example in MATLAB

    Recent Posts

    • ChatGPT Subscription Plans
    • Stellar Converter for Database
    • Stellar Log Analyzer for MySQL
    • Stellar Repair for MySQL
    • ChatGPT Capabilities
    • How to secure your SQL Database: Tips and Tricks
    • ChatGPT4 Conversational AI Features
    • Shaping the Future of Development: Exploring Key Trends in Software Engineering
    • Improving Java Performance with Multithreading
    • Open-source Vector Databases

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com