CUNY offers a campus-wide license to MATLAB, Simulink, and all companion products. All faculty, researchers, and students are eligible to download and install these products on their university computers as well as their personally-owned computers.
- You need to have a valid CUNY email address, either in the format citymail or ccny email.
- You need to renew license in your Matlab application once a year at the end of November.
Preparation: Mathworks account
If you don’t have a Mathworks account associated with your CUNY email address yet, go to the following URL to create and account:
The campus local license administrator will help you to link CUNY site license to your Mathworks account.
Once your local license administrator gives the license activation code, go to your account at Mathworks website and click on link license:
Download the installer
Download the Matlab installer from Mathworks.
Run the installer
When you run the matlab installer, choose installation method with “Log in with a MathWorks Account”.
Then Login with your MathWorks account.
After you login, you will be presented with license choice and please select this license
|1111017||Standard – Individual|
Renew the license
The license renewal option is hidden under Help -> Licensing -> Update Current Licenses. You will need to do this every year at the end of November or earl December.
Servers with preinstalled Matlab
Levich Institute and Chemical Engineering department offer following computing resources that have preinstalled Matlab. Matlab runs best on your own computer but the servers fit situation like:
- One needs to run prolonged sessions of Matlab jobs
- One’s Matlab jobs require memory and CPU more than a personal computer can handle.
Cheme Linux server
Poincare Linux server
Chemical Engineering Citrix server
|Account Application||Andrew Eng <email@example.com>|
|Remark||This server offers Matlab through non-persistent virtual desktop|
You need City College VPN account to access the server cheme.engr.ccny.cuny.edu and poincare.engr.ccny.cuny.edu by ssh.
You can run Matlab Online provided by Mathworks within a browser window if you have a Mathworks account with CCNY site license.
- Matlab Onramp: Learn the essentials of MATLAB® through this free, two-hour introductory interactive tutorial on commonly used features and workflows.
- MIT Open course: Short videos serve as introduction to Matlab programming for beginners.
- Physical Modeling in MATLAB by Allen Downey: learn some programming, some modeling, and some simulation in this free book.
- MATLAB: A Practical Introduction to Programming and Problem Solving (5th edition) by Stormmy Attaway: winner of TAA’s 2017 Textbook Excellence Award (“Texty”).
Matlab Quick Reference
The Matlab Work Environment
Some commands have links to syntax details and examples.
|clc||Clear Command Window|
|clear||Remove items from workspace, freeing up system memory|
|close all||Close all plots|
|doc function||Display documentation page in Help browser|
|help||Help for functions in Command Window|
|ver||Version information for MathWorks products|
|% some comment text||Comment text|
|CTRL+C||Abort the current operation|
|format short||Display 4 decimal places|
|format long||Display 15 decimal places|
|disp(‘some text’)||Print some text|
|a = 3||Define variable a to be 3|
|x = [1, 2, 3]||Set x to be the row vector [1, 2, 3]|
|x = [1; 2; 3]||Set x to be the column vector [1, 2, 3]T|
|A = [1, 2, 3, 4, 5, 6;|
7, 8, 9, 10, 11, 12]
|Set A to be a 2 × 6 matrix|
|x(2) = 7||Change x from [1, 2, 3] to [1, 7, 3]|
|A(2,1) = 0||Change A2,1 from 5 to 0|
Matrices and Vectors
|zeros(12, 5)||Make a 12 × 5 matrix of zeros|
|ones(12, 5)||Make a 12 × 5 matrix of ones|
|eye(5)||Make a 5 × 5 identity matrix|
|eye(12, 5)||Make a 12 × 5 identity matrix|
|linspace(1.4, 6.3, 1004)||Make a vector with 1004 elements evenly spaced between 1.4 and 6.3|
|logspace(1.4, 6.3, 1004)||Make a vector with 1004 elements where the log of the spacing is|
evenly increasing between 1.4 and 6.3
|7:15||Row vector of 7, 8, . . . , 14, 15|
Operations on Matrices and Vectors
|3 * x||Multiply every element of x by 3|
|x + 2||Add 2 to every element of x|
|x + y||Element-wise addition of two vectors x and y|
|A * y||Product of a matrix and vector|
|A * B||Product of two matrices|
|A .* B||Element-wise product of two matrices|
|A ^ 3||Square matrix A to the third power|
|A .^ 3||Every element of A to the third power|
|cos(A)||Compute the cosine of every element of A|
|abs(A)||Compute the absolute values of every element of A|
|A’||Transpose of A|
|inv(A)||Compute the inverse of A|
|det(A)||Compute the determinant of A|
|eig(A)||Compute the eigenvalues of A|
|size(A)||Get the size of A|
Slicing Matrices and vectors
|x(2:12)||The 2nd to the 12th elements of x|
|x(2:end)||The 2nd to the last elements of x|
|x(1:3:end)||Every third element of x from the first to last|
|A(5,:)||Get the 5th row of A|
|A(:,5)||Get the 5th column of A|
|A(5, 1:3)||Get the first to third elements in the 5th row|
|NaN||Not a number (i.e. 0/0)|
|realmax||Largest positive floating-point number|
|realmin||Smallest positive floating-point number|
for k = 1:5 disp(k); end
k = 0; while k < 7 k = k + 1; end
a = 10 a == 5 % Test if a is equal to 5 false a == 10 % Test if a is equal to 10 true a >= 5 % Test if a is greater than or equal to 5 true a < 11 % Test if a is less than 11 true a ~= 4 % Test if a is not equal to 4 true a > 1 && a ~= 10 % Test if a is greater than 1 AND not equal to 10 false a > 1 || a ~= 10 % Test if a is greater than 1 OR not equal to 10 true
if a > 10 disp('Greater than 10'); elseif a == 5 disp('a is 5'); else disp('Neither condition met'); end
function output = addNumbers(x, y) output = x + y; end addNumbers(10, -5) 5
|plot(x,y)||Plot y versus x (must be the same length)|
|loglog(x,y)||Plot y versus x on a log-log scale (both axes have a logarithmic scale)|
|semilogx(x, y)||Plot y versus x with x on a log scale|
|semilogy(x, y)||Plot y versus x with y on a log scale|
|axis equal||Force the x and y axes to be scaled equally|
|title(‘A Title’)||Add a title to the plot|
|xlabel(‘x label’)||Add a label to the x axis|
|ylabel(‘y label’)||Add a label to the y axis|
|legend(‘foo’, ‘bar’)||Label 2 curves for the plot|
|grid||Add a grid to the plot|
|hold on||Multiple plots on single figure|
|figure||Start a new plot|
x = linspace(-3*pi, 3*pi, 1000); y1 = sin(x); y2 = cos(x); plot(x, y1, 'k-'); % Plot sin(x) as a black line hold on % Now we can add another curve plot(x, y2, 'r-'); % Plot cos(x) as a red line % Set the axis limits axis([-3*pi, 3*pi, -1.5, 1.5]) % Add axis labels xlabel('x'); ylabel('y'); % Add a title title('A plot of cos(x) and sin(x)'); % Add a legend legend('sin(x)', 'cos(x)');