Repository of MATLAB example code for referencing, since I always forget the syntax for the same things and find myself googling the same terms over and over again.
Commenting:
Ctrl + R
: Comment selected linesCtrl + T
: Un-comment selected linesCtrl + I
: Smart indent
Running code:
F5
: Run the whole scriptCtrl + Enter
: Run the current section
I place this at the top of every script I write. Close all windows opened, clear all variables from the workspace, and clear the command window.
clear variables;
close all;
clc;
Create an empty sum variable, count that variable up to 100 in a loop.
sum = 0;
for i = 1:100
sum = sum+1;
end
Print a string + a variable using three different methods.
disp("Sum: ");disp(sum);
disp("Sum: " + sum);
fprintf("Sum: %d\n", sum);