Lecture2_Computing
Lecture2_Computing
GET211
Emmanuel Ali
Ayibaemi Ledum
1 Introduction
2 Introduction to MATLAB
Desktop Layout
The MATLAB desktop is highly customizable, allowing users to arrange
various tools and windows according to their preferences.
It typically includes the Command Window, Workspace, Current Folder,
and Editor, among other tools.
Command Window
This is the primary interface for entering commands and executing
MATLAB code interactively.
It displays the MATLAB prompt (>>) where users can type commands
directly.
Results of computations are immediately displayed here.
It also shows error messages and warnings.
Characteristics of Variables:
- Named Storage Location: Each variable has a unique name (identifier),
which is used to access the stored value.
- Data Type: Variables can store different types of data (integers,
floating-point numbers, characters, etc.).
- Mutable: Variables can change value over time during the execution of a
program.
- Scope: Variables have a defined region (scope) where they can be accessed.
This can be local (within a function) or global (across the entire program).
- Lifetime: A variable’s lifetime refers to the period during which the variable
exists in memory (from its creation to its destruction).
Emmanuel Ali, Ayibaemi Ledum 1st Semester October 20, 2024 8 / 23
Variable Declaration and Assignment
1 myVariableName
2 totalSum
Pascal Case (PascalCase): Similar to camelCase, but the first letter of every word (including the first
word) is capitalized. Often used for naming classes
1 MyVariableName
2 TotalSum
Snake Case (snake case): In snake case, all letters are lowercase, and words are separated by
underscores. Often used in variable names.
1 my_variable_name
2 total_sum
Uppercase with Underscores (UPPER CASE:) All letters are uppercase, and words are separated
by underscores. This convention is often used for constants.
MAX VALUE
PI CONSTANT
Checking Variables
- who: List variables in the workspace.
- whos: Provides a detailed list of variables, including type and size
information.
- exist(’varname’, ’var’): Checks if a variable with the name ’varname’
exists in the workspace.
Clearing Variables
- clear x: Clears the specific variable ‘x‘ from the workspace.
- clear: Clears all variables from the workspace.
- clearvars: Provides more flexibility in clearing variables by name or
pattern.
- clc: Clears the Command Window but does not affect workspace
variables.