FWD Skill Zone
  • home
  • Power
    • Breadboard Power Supply
    • Variable Power Supply
    • DC to DC Boost Converter
  • Robotics
    • Braccio Robotic Arm
    • Voice-activated robotic arm
    • Smart Robot Car
  • Electronics
    • Arduino 101
    • Arduino 102
    • Arduino 103
    • Short Range Radar System
  • 3D print
  • VHDL
    • Intro to VHDL
    • 2 to 4 Binary Decoder
    • 3 to 8 Binary Decoder
    • Universal Shift Register
  • Verilog
    • Intro to Verilog
    • Verilog Construction
    • Verilog Examples
  • Machine Learning
    • Deep Learning
    • Transfer Learning
  • Contact us
  • home
  • Power
    • Breadboard Power Supply
    • Variable Power Supply
    • DC to DC Boost Converter
  • Robotics
    • Braccio Robotic Arm
    • Voice-activated robotic arm
    • Smart Robot Car
  • Electronics
    • Arduino 101
    • Arduino 102
    • Arduino 103
    • Short Range Radar System
  • 3D print
  • VHDL
    • Intro to VHDL
    • 2 to 4 Binary Decoder
    • 3 to 8 Binary Decoder
    • Universal Shift Register
  • Verilog
    • Intro to Verilog
    • Verilog Construction
    • Verilog Examples
  • Machine Learning
    • Deep Learning
    • Transfer Learning
  • Contact us

MATLAB For Beginners

MATLAB (matrix laboratory) is a high-level script programming language and interactive environment for numerical computation, visualization and programming. MATLAB is developed by the MathWorks company. It started out as a matrix programming language but now It can run both under interactive sessions and as a batch job.

Engineers and Scientists use MATLAB because it combines a desktop environment tuned for iterative analysis and design processes with a programming language that expresses matrix and array mathematics directly. Today we use MATLAB to solve complex mathematical problems using Data Analytics, Wireless Communications, Deep Learning,  Computer Vision, Signal Processing, Robotics, and Control System toolboxes. 
​This tutorial is to help students understand the basics and few advanced functionality of MATLAB. After completing this tutorial you will gain basic understanding of the MATLAB program in order to advance to the next level. Good luck!
Desktop Basics
​
When you start MATLAB®, the desktop appears in its default layout.
Picture
 Arrays and Matrices
​Array Creation:
To create an array with four elements in a single row, separate the elements with either a comma (,) or a space. 
Enter the following into the command window. (This type of array is a row vector.)
a = [1 2 3 4]
a = 1×4

     1     2     3     4​

create a 1-by-5 column vector of zeros.
z = zeros(1,5)
z = 5×1

     0     0     0     0     0​

To create a matrix that has multiple rows, separate the rows with semicolons.
a = [1 2 3; 4 5 6; 7 8 10]
a = 3×3
     1     2     3
     4     5     6
     7     8    10
​

You can add a value to an existing matrix.
a + 10
​ans = 3×3
    11    12    13
    14    15    16
    17    18    20

Below are some more examples.

\(\color{red}{\heartsuit}\) Vectors

 Script a:

clc; clear;
format short
a= (3:4:27)

-----ans-----------------
a =  ​3     7    11    15    19    23    27
​---------------------------


​Script b:

clc; clear;
format short
b= linspace(68,12,8)

​-----ans------------
b =  68    60    52    44    36    28    20    12
​----------------------


​Script c:

clc; clear;
format short
c = (0:1:10)

-----ans------------
c =  Columns 1 through 12
     0     1     2     3     4     5     6     7     8     9    10  
​----------------------

Script d:

​clc; clear;
format short
d = linspace (4,4,9)

​-----ans------------
d =  ​4     4     4     4     4     4     4     4     4
​----------------------


​Script e:
​
clc; clear;
format short
e (1:7)=7

-----ans------------
e =  ​7     7     7     7     7     7     7
​--------------------


​Script f:

clear; clc;
format short
p(6)= 5.9

-----ans------------
f =  ​0         0         0         0         0    5.9000
​--------------------


\(\color{red}{\star}\)  Matrix

A = ones(4)
-----ans---------------
​     1     1     1     1
     1     1     1     1
     1     1     1     1
     1     1     1     1
​---------------------------


B = zeros(5,4)
-----ans---------------
​     0     0     0     0
     0     0     0     0
     0     0     0     0
     0     0     0     0
     0     0     0     0
​--------------------------

C= eye(4)
-----ans---------------
​     1     0     0     0
     0     1     0     0
     0     0     1     0
     0     0     0     1
​--------------------------

​D = eye(3,4)
-----ans---------------
​     1     0     0     0
     0     1     0     0
     0     0     1     0
​-------------------------

E = diag(1:4)
-----ans---------------
​     1     0     0     0
     0     2     0     0
     0     0     3     0
     0     0     0     4
​---------------------------
F = randi(5,5)
----ans---------------------
     2     5     4     3     2
     2     4     1     4     4
     5     1     4     4     1
     1     2     1     5     1
     5     2     4     5     4
-------------------------------

G= [linspace(6,6,4); linspace(8,8,4)]'
-----ans------------
​     6     8
     6     8
     6     8
     6     8
​---------------------

​
H= [ones(3,4); (8:-2:2)]
-----ans----------------
​     1     1     1     1
     1     1     1     1
     1     1     1     1
     8     6     4     2
​--------------------------

I= [zeros(3,4) (8:-1:6)']
-----ans---------------------
     0     0     0     0     8
     0     0     0     0     7
     0     0     0     0     6
​-------------------------------

​J = [zeros(2,4); zeros(1,2) (4:-2:2)]
-----ans----------------
     0     0     0     0
     0     0     0     0
     0     0     4     2
​---------------------------

Now we will solve some textbook questions.
​​[Text book -MATLAB: An Introduction with Applications, Amos Gialt]

​\(\color{red}{\spadesuit}\)  Calculate the following expressions using MatLab script

\(\color{red}{a  = (5- {19/ 7}+2.5^3)^2}\)

​Script:
​clc;
a = (5-19/7+2.5^3)^2;
fprintf('a = %0.4f \n', a );
​
​-----ans------------
​​a = 320.7937
​---------------------
​
​\(\color{red}{b = \sqrt[3]{8+ {\frac {80}{2.6}}} + e^{3.5}}\)

Script:
clc;
​b = nthroot(8+(80/2.6),3)+ exp(3.5);
​​fprintf('a = %0.4f \n', b);

-----ans------------
​​b = 36.5000
​---------------------​
\(\color{red}{c = 7*3.1+ \frac {\sqrt {120}}{ 5} -15^ {5/3}}\)

Script:
​clc;
c= 7*3.1+(sqrt(120)/5)-15^(5/3);
disp (b )
​
​-------ans----------
​​c = -67.3421
​---------------------
​
​\(\color{red}{​d = \frac{\sin{0.2 /\pi}} {\cos{\pi/6}}+\tan(72°​)}​\)

Script:
clc;
d = (sin(0.2*pi)/(cos(pi/6)))+tand(72);
disp (a)

-----ans------------
​​      3.7564
​---------------------

Advanced  MatLab applications ​

Latex codes for website​
Matlab script:
​       syms x phi
       latex(x^2 + 1/x)
       latex(sin(pi*x) + phi)
----ans--------------------
ans =
    '\frac{1}{x}+x^2'
ans =
    '\varphi +\sin\left(\pi \,x\right)'
-----------------------------
Use "MatJax" or similar JavaScript platform to generate any math equations.
​
Example:
​Using the above Matlab generated Latex code, you can generate the following expressions in your webpage.

=> \pi +\sin\left(\pi \,x\right)
\(\color{red}{prints:   }\) \(\pi +\sin\left(\pi \,x\right)\)

=>  \varphi +\sin\left(\pi \,x\right)
 \(\color{red}{prints:   }\) \(\varphi +\sin\left(\pi \,x\right)\)

​This is exactly how the math equations are generated in this website.


Picture
Back to top


PAGE TAGS: AutoCAD, CAD, CATIA, Digital Logic Design, Matlab, VHDL, Links, Programming, Django, Python


  • home
  • Power
    • Breadboard Power Supply
    • Variable Power Supply
    • DC to DC Boost Converter
  • Robotics
    • Braccio Robotic Arm
    • Voice-activated robotic arm
    • Smart Robot Car
  • Electronics
    • Arduino 101
    • Arduino 102
    • Arduino 103
    • Short Range Radar System
  • 3D print
  • VHDL
    • Intro to VHDL
    • 2 to 4 Binary Decoder
    • 3 to 8 Binary Decoder
    • Universal Shift Register
  • Verilog
    • Intro to Verilog
    • Verilog Construction
    • Verilog Examples
  • Machine Learning
    • Deep Learning
    • Transfer Learning
  • Contact us