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 plots 

 plot   Linear plot.
plot(X,Y) plots vector Y versus vector X. If X or Y is a matrix, then the vector is plotted versus the rows or columns of the matrix, whichever line up.  If X is a scalar and Y is a vector, disconnected line objects are created and plotted as discrete points vertically at X.

Various line types, plot symbols and colors may be obtained with plot(X,Y,S) where S is a character string made from one element from any or all the following 3 options:
COLOR: b - blue,    g - green,   r - red,   c - cyan,   m - magenta,  y - yellow,  k - black,   w - white
SYMBOL: . point, o  circle, x   x-mark, +   plus, * star, s square, d diamond, v triangle (down)
LINE TYPE:  - solid, : dotted, -. dashdot, -- dashed, (none) no line
​Example:
x = -pi:pi/10:pi;
       y = tan(sin(x)) - sin(tan(x));
       plot(x,y,'--rs','LineWidth',2,...
                       'MarkerEdgeColor','k',...
                       'MarkerFaceColor','g',...
                       'MarkerSize',10)​
Picture

​
\(\color{red}{\diamondsuit}\)Single plot


Script a:
x = 0:0.1:5; 
​\(\color{green}{\text{  % 0.1 spacing creates a smooth curve}}\)
y = x.^2 - 10.*sqrt(x)+2;
​   

    plot (x,y,'b');
    grid;
    xlabel ('x');
    ylabel ('y');
Picture

cript b:
x = 0:pi/100:2*pi;
y = sin(x);

  plot (x,y,'r');
​\(\color{green}{\text{  % 'r' creates red color}}\)

  grid;
  xlabel ('x');
  ylabel ('sin(x)  ', 'rotation', 0);
Picture

​
\(\color{red}{\clubsuit}\)  Multiple Plots

Script a: 
x = linspace(-2*pi,2*pi);
y1 = sin(x);
y2 = cos(x);
plot(x,y1,x,y2);
Picture
script c:
subplot(2,1,1);
x = linspace(0,10);    y1 = sin(x);
subplot(3,1,1);\(\color{green}{\text{  % 3 rows by 1 column, the first row}}\)
plot(x,y1,'r')
subplot(3,1,2);\(\color{green}{\text{  % 3 rows by 1 column, the second row}}\)
y2 = sin(3*x);
plot(x,y2, 'b')
subplot(3,1,3);\(\color{green}{\text{  % 3 rows by 1 column, the third row}}\)
plot(x,y1,'r',x,y2, 'b')
Picture

Script b:
'script a' can also be modified as:
x = linspace(-2*pi,2*pi);
y1 = sin(x);
y2 = cos(x);
p1 = plot(x,y1,'linewidth',2 );
grid;
hold on
p2 = plot(x,y2, '*--' );
xlabel('x')
ylabel ('y', 'rotation', 0)
legend ('sin(x)', 'cos(x)', 'location', 'best')
title ('Sine VS Cosine')
hold off
Picture

​Script d: 
​'script c' can also be modified as:
subplot(2,1,1);
x = linspace(0,10);      y1 = sin(x);
subplot(2,2,1);
plot(x,y1,'r')
subplot(2,2,2);
y2 = sin(3*x);
plot(x,y2, 'b')
subplot(2,2,[3,4]);\(\color{green}{\text{  % spans the lower half of the figure}}\)
plot(x,y1,'r',x,y2, 'b')
Picture

Generate N=100,000 random numbers. Then use the MATLAB “hist” function to plot the results. Depending on the limits set for the ranges of the data for the “hist” function, the histogram plots will be slightly different.

Matlab script:
clear; close all;
N=100000;
R=rand(N,1);
Range =0.0:.1:1.0;
[y,R]=hist(R,Range);
bar(R,y)
grid MINOR
title('SAMPLE HISTOGRAM')
xlabel('Random number R');
ylabel('Number of occurrences')

​Matlab output:
Click to Zoom in

Here is the same script but for a different range.
​
clear; close all;
N=100000;
R=rand(N,1);
Range=0.05:.1:0.95;
[y,R]=hist(R,Range);
bar(R,y)
grid MINOR
title('SAMPLE HISTOGRAM')
xlabel('Random number R');
ylabel('Number of occurrences')
​Matlab output:
Picture

Picture
Back to top


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


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.
​
  • 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