In MATLAB, there are 5 main operators that are key to know:
These operators follow PEMDAS for their order of execution. Let's experiment with some numeric variables using these operators.
matlab
x = 4; y = 1; z = 3;
x - y; % output: 3
z + y * x; % output: 7
(z + y) * x; % output: 16
num = z^(3/4); % output: 2.2795
Two built-in MATLAB functions that are quite useful are ceil() and floor(). ceil() and floor() round numbers up and down, respectively. Let's try it out!
matlab
num = 5.4;
ceil(num); % output: 6
floor(num); % output: 5
Another handy function for more precise rounding is the 'round()' function. The round function can use two input to the function, the first for the variable to round, and the second for the decimal place to round to. There are some extra options as well, but those are for another time.
matlab
num2 = 3.4762;
round(num2, 2); % output: 3.48