Welcome to Python!

Python for MATLAB Users

Justin Kiggins

Product Manager

Prerequisite: Manipulating matrices in MATLAB

% Example of manipulating matrices in MATLAB

v = [16 5 9 4 2 11 7 14];
disp(v(5:end))

A = magic(4);
disp(A(2:4,1:2))

A(A>12) = 10;

disp(A(:,1))
Python for MATLAB Users

Prerequisite: Plotting data in MATLAB

% Example of plotting data in MATLAB
figure
plot(t,y,'b-')
xlabel('Time (s)')
ylabel('Sensor A')

figure
scatter(y1,y2,'go')
xlabel('Sensor A')
ylabel('Sensor B')

figure
histogram(y1,[0:0.01:1])
Python for MATLAB Users

Prerequisite: Control flow of MATLAB scripts

% Example of control flow in MATLAB

fid = fopen('magic.m','r');
count = 0;
while ~feof(fid)
    line = fgetl(fid);
    if isempty(line) || strncmp(line,'%',1) || ~ischar(line)
        continue
    end
    count = count + 1;
end
count
Python for MATLAB Users

If you don't know MATLAB...

Python for MATLAB Users

Python does more than Data Science

  • General purpose programming language
    • Integrate machine learning models into large-scale applications
    • Query data from public APIs
    • Build websites that can handle large traffic volumes
Python for MATLAB Users

Getting started with data types

  • Integer
  • Float
  • Boolean
  • String
# Integer
x = 1

print(x)
type(x)
1

<class 'int'>

 

   

 

# Float
x = 1.0  
print(x)

type(x)
1.0

<class 'float'>
Python for MATLAB Users

Mathematical operators

Operation Python Operator
Addition +
Subtraction -
Multiplication *
Division /
Exponentiation **
a = 3 + 12
print(a)
15
b = 4 * 5.0
print(b)
20.0
Python for MATLAB Users

$ area = \pi r^2 $

radius = 5
pi = 3.14
area = pi * (radius ** 2)
print(area)
78.5

Warning: Do NOT use the caret operator, ^

# This won't take 4 to the second power
print(4 ^ 2)
# This is the bitwise XOR
6
Python for MATLAB Users

Let's get started!

Python for MATLAB Users

Preparing Video For Download...