• Skip to main content
  • Skip to secondary menu
  • Skip to primary sidebar
  • Skip to footer
Circuits Gallery

Circuits Gallery

All about Electronics and Circuits

  • Home
  • Basics
    • Components
    • Wiring
    • Circuitry
    • Oscilloscope
    • Conductivity
  • Project
    • Using 555 Timer
    • Using Op-Amp
  • MicroController
    • PIC
  • Arduino
  • Simulation
  • Digital
  • Communication
  • How To
  • About Us

How to Plot a 2d Function in MATLAB? Basic Steps for MATLAB Plotting

March 28, 2022 by Charles Clark Leave a Comment

You can easily plot different functions using MATLAB. To plot a 2D function in MATLAB you must first choose an independent variable. Let it be ‘x’. This variable will form an axis of the plot, more likely the horizontal or x-axis. The vertical component of the plot is then found by using the function of this independent variable.

Each point in the plot has a vertical and horizontal component. First, the independent variable and its range must be defined. At the same time, the number of points to be used in the plot can also be declared.

For example, we are going to plot the ‘Sine’, and the ‘Sinc’ function. The program is self-explanatory. We added some labels to the plotted graph to make clear the programming steps.

How to Plot a 2d Function in Matlab

Program for How to Plot a 2d Function in MATLAB

Clear all;
clc;
close all;
set(0,'defaultlinelinewidth',2); %Intensity of lines
t=-100:.005:100; %Time Samples from -100 to 100 with an interval of 0.005
s=sin(t); %Assigning Sin(x) to a variable 's'
subplot(2,1,1); %The ploting frame divided in to 2 rows and this fig appear at first
plot(t,s,'R'); %Plotting 't' on X-Axis Vs 's' on Y-Axis,'R' indicate the Colour 'RED'
title('Plot of Sine Function');%Title of the plot
xlabel('Time'); %Name of X-Axis
ylabel('Amplitude');%Name of Y-Axis
axis([0 20 -2 2]); %X-Axis varies from 0 to 20 and Y-Axis from -2 to 2
grid on; %Enable Grid lines
z=2*sin(t)./t; %Assigning Sin(x)/x to a variable 'z'
subplot(2,1,2); %To ploting frame divided in to 2 rows and this fig appear at second
plot(t,z,'B'); %Plotting 't' on X-Axis Vs 'z' on Y-Axis,'B' indicate the Colour 'BLUE'
title('Plot of Sinc Function');%Title of the plot
xlabel('Time'); %Name of X-Axis
ylabel('Amplitude');%Name of Y-Axis
axis([-20 20 -1 3]);%X-Axis varies from -20 to 20 and Y-Axis from -1 to 3
grid on; %Enable Grid lines

Plotted Output

Conclusion

This guideline provides the answer to how to plot a 2d function in MATLAB for any graph you need. Sine and Sinc are used as instances since they are the most familiar ones within the engineering community.

Filed Under: Basics, How To

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

More To See

How Far Can You Run Low Voltage Lighting

How Far Can You Run Low Voltage Lighting? Exploring the Limits of Low Voltage Lighting Installations

What is the Difference between RC Coupling and Transformer Coupling

What is the Difference between RC Coupling and Transformer Coupling? In-Depth Guide

Oscilloscope Probe X1 X10 Difference

Oscilloscope Probe X1 X10 Difference | Detection and Compensation of Probes

How to Measure Amps on 240V Circuit With Multimeter

How to Measure Amps on 240V Circuit With Multimeter | Step-By-Step Guide

More About

  • Arduino
  • Basics
  • Circuitry
  • Communication
  • Components
  • Conductivity
  • Digital
  • How To
  • MicroController
  • Oscilloscope
  • PIC
  • Project
  • Simulation
  • Using 555 Timer
  • Using Op-Amp
  • Wiring

Footer

QUICK LINKS

  • About Us
  • Privacy Policy
  • Terms and Conditions
  • Contact

AFFILIATE DISCLOSER

Circuits Gallery is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for website owners to earn advertising fees by advertising and linking to amazon (.com, .co.uk, .ca etc) and any other website that may be affiliated with Amazon Service LLC Associates Program

© 2023 · Circuits Gallery | All Rights Reserved