Week 1 Part 4 Fundamentals
Week 1 Part 4 Fundamentals
Data types
x = 6;
MATLAB computes the value of the expression on the right of the equals sign and then
assigns that value to the variable named on the left.
If the variable on the left already exists, it is overwritten with the new value.
The expression to the right of the equals sign can be anything that MATLAB can
evaluate:
x = 42;
y = x/6; % y has the value 7
x = 3.14; % y still has the value 7
y = y - 1; % y is now 6
Run the code using the play button and see the output:
6*7
Entering just the name of a variable, with no assignment or calculation, returns the
current value of that variable:
x
x=
3.1400
Enter the command below in the command window, do you see the output?
y = 3.14;
Note MATLAB is case sensitive: name is not the same as Name or NAME.
Enter the command below in the command window, do you see that there was an
additional variable “Y” that was created?
Y = 3.14;
Although the Command Window shows a record of the commands issued and the output
returned, this record is not editable: only the current line can be edited.
Pressing the up-arrow key on your keyboard at the command prompt brings up the
Command History window. In the Command History you can:
• Scroll through commands with the up and down arrow keys.
• Select commands with the mouse.
• Select multiple commands (use Shift-click or Ctrl-click).
• Edit recalled commands.
• Re-enter commands.
If you partially enter a command, the Command History will be filtered to show only
commands that match the portion entered. Use the window action menu to adjust the
filtering options.
Later we’ll see how we can use the Command History to recall commands and help
create scripts to automate your tasks.
© 2023 Introduction to Programming in MATLAB (1), Fundamentals 11
Variables in the Base Workspace
Commands executed in the command window or in a Live Script are stored in the form of
MATLAB variables in the base workspace (MATLAB memory).
The contents of the base workspace are shown in the Workspace browser window. The
browser displays the names of the variables currently in memory and (optionally)
information about the variables (e.g., size and class).
You can rename a variable by right-clicking it in the Workspace browser and choosing
Rename from the context menu.
Right-clicking on the Name button at the top of the Workspace browser displays a context
menu from which you can choose which information to display about the variables.
• Week_1_Part_4_Fundamentals.mlx