Please don't read this. It requires a lot of formatting.
For now, you can read all of this in a PDF [here](https://gitlab.windenergy.dtu.dk/python-at-risoe/scientific-python-workshops/2-getting-started/blob/master/matlab_vs_python.pdf).
# Placing text below so I don't lose it, but it is not useful to others now
Originally from [this page](http://reactorlab.net/resources-folder/matlab/P_to_M.html)
but modified to 1) be in markdown, 2) fix some errors, and 3) add more detail.
<table>
<tr>
<th>Python</th>
<th>Matlab</th>
</tr>
<tr>
<td><ul>
<li>numeric variables are double precision if decimal added</li>
</ul>
<pre><code>a = 5. # this is a float
a = 5 # this is an int</code></pre>
</td>
<td><ul>
<li>numeric variables are double precision by default</li>
</ul>
<pre><code>a = 5.0; % this is a double</code></pre>
</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
</tr>
</table>
# test
numeric arrays are objects defined in NumPy package <br/> indexes start at 0 in Python <br/> structures are defined by indentation, no 'end' <br/>`A = np.empty(10) # initialize array A`| array indexes start at 1 in Matlab <br/> indentation is for readability only <br/>`for i=1:10`<br/>` A(i) = i;`
for i in range(1,11): | end
A.append(i) | A % display contents of A
print(A[i-1]) |
|
# repeat which prints a series of |
# values | for i=0:2:10
| fprintf(' %i \n', i)
for i in range(0,11,2): | end
print(i) |
|
# initialize an identity matrix |
| % MATLAB has built-in functions for
# import the numpy library for matrix operations | % common array initializations
|
import numpy as np | B = eye(100);
|
B = np.identity(3) |
|
# declare and initialize an array, | C = [1, 2, 3]; % or C = [1 2 3];
# known as a list in Python |
|
C = [1, 2, 3] |
|
# initialize and print an array |
# array name = arange(start,stop,step) | % array name = [start:increment:end];
|
import numpy as np |
C = np.arange(2,10,2) | C = [2:2:8] % leave off ; to display value
print(C) |
|
# print an array element on screen |
# array indexes start at 0 | % array indexes start at 1
|
print(C[1]) | C(2)
|
# prints 4 using C from above table cell | % prints 4 using C from above table cell