Table of Contents

Basic Syntax

End of Line

MATLAB recognizes and compiles lines without the need for an operator; however, this will display information in the terminal, making it harder to spot the result you were looking for.++

To hide operations, use the semicolon ( ; ).

However, if you want consecutive lines to be considered as one, you can use an ellipsis ( … ).

%% End of Line Operations
text1 = "This line will be printed"
text2 = "The semicolon keeps this line hidden";
text3 = "If you want to continue a line" ...
    + " use elipsis!"

Output:

image.png

https://www.mathworks.com/help/matlab/learn_matlab/desktop.html

MATLAB as a Calculator

MATLAB can be used as a powerful calculator. It uses the standard computer symbols for common arithmetic operations such as addition ( + ), subtraction ( - ), multiplication ( * ), division ( / ), and exponentiation ( ^ ) . Parentheses may be used to control the order of operations just like on paper .

Basic operations

Arithmetic – You can type expressions directly into the Command Window. For example, 3+4*(1+6/3) returns 15 . Assigning the result to a variable is as simple as x=3+4*(1+6/3), which makes x equal to 15. Suppressing output – If you end a line with a semicolon ( ; ), MATLAB performs the calculation without displaying the result. Clearing variables – Use the clear command to remove variables from memory. For instance, after computing a variable x , running clear will remove it so that typing x again produces an “unrecognized variable” message. Exponentiation – Exponentiation uses the ^ operator. For example, 3^4 evaluates to 81.

Sample Exercise

Evaluate the following expressions and store the results in variables:

matlab
CopyEdit
a = 5^2 + 3*4;      % Expected: 37
b = (2 + 3)*(4 + 1); % Expected: 25
c = (7 - 2)^2 / 5;   % Expected: 5

https://sabs-r3.github.io/ScientificComputingInMatlab/unit_1_basic_introduction_to_matlab/04_using_matlab_as_a_calculator/