# MATLAB – Plots in Detail

• Last Updated : 16 Dec, 2022

Prerequisite: Introduction to MATLAB
MATLAB is a powerful programming language, that can be used to draw various plots used in machine learning, deep learning, computer vision, and big data programming. Let us start with coding for plots in MATLAB.

Example 1: Let us first understand the simple plot :

## MATLAB

 % angle from 0 to 2pitheta = 0 : 0.01 : 2 * pi; % sin function works on an arrayf = sin(theta);% 2D plotplot(theta, f, 'b') % label for X-axisxlabel('\theta'); % label for Y-axisylabel('sin(\theta)');title('Plot of Sine function')

Output :
In the above code, the sine graph is plotted. Here as seen from the code we first define theta value of the sine plot, then build an array out of it and that function is finally plotted on the graph as shown in the output. Example 2: Here we will plot the helix which is a 3-dimensional figure. As we all know from basic geometry that a helix is formed from the combination of the sine function and cosine function by declaring the value of theta and then iterating it over the same function. Try to visualize the output.

## MATLAB

 % angle from 0 to 2pitheta = 0:0.01:2*pi; % sin function works on an arrayf = sin(theta); % 3D plott = 0 : pi / 50 : 10 * pi; % open a new figurefigure % 3D plot (helix)plot3(sin(t), cos(t), t);

Output : Example 3: This is purely a complex plot, MATLAB being a highly visualization language for statistics and plots. We have a scope to plot such types of graphs here. Here we have plotted the Riemann surface, in a 3D space. Try to visualize the output. Such types of complex functions can be plotted in MATLAB.

## MATLAB

 % angle from 0 to 2pitheta = 0 : 0.01 : 2 * pi; % sin function works on an arrayf = sin(theta); t = 0 : pi / 50 : 10 * pi; % open a new figurefigure %  Riemann surfaces figurecplxroot(5) % plots the Riemann Surface for w = z ^ (1 / 5)

Output :

My Personal Notes arrow_drop_up