The first time you open MATLAB
This is a short introduction to opening MATLAB for the first time.
Layout
The default layout of MATLAB looks like
In the command window you can insert commands
In the workspace you can see the current value of all variables
Folder
MATLAB starts up in it's default folder. This could e.g. be
Each time you start a new project it is a good idea to create a new folder for your MATLAB files. This can be done from within MATLAB with a right-click in the "Current Folder" window and then using "New Folder". New files can be created in the same way or by using the "New" button in the uppermost left corner.
I have now created a sub-folder called project with two files it in: script.m and livescript.mlx. The files can be opened in the editor by double-clicking on them.
File-types
Script-files (.m) are the most basic MATLAB files. They collect commands in sections delimited by %%.
- All lines end with a ;
- The script file can be run på pressing F5.
- The individual sections can be run by pressing Crtl+Enter.
- Comments can be added with a single %.
- Text output is shown in the command window.
- Figure output is shown in pop-ups.
In the editor it looks like
LiveScript-files (.mlx) are the next most basic MATLAB files
- All lines end with a ;
- The script file can be run på pressing F5.
- The individual sections can be run by pressing Crtl+Enter.
- Comments can be added with a single %.
- Both text and figure output is shown continuously on the right side (next to the workspace window).
- Using the icons in the ribbon in the top of the window text, headings and equations can be added (alt-enter shift alternates between text and code).
- Right-clicking in the output window allow you to clear it.
In the editor it looks like
Note that variables created when running scripts and live-scripts can still be seen in the workspace window. In the command window you can also interact with the variables and e.g. display them.
Commands
Basic commands you need to know already now is
- disp(variable); displayes the content of a variable.
- clear; clear all memory .
- clc; clear the command window.
- doc function shows you what the function does
- pressing crtl+c kills the running program.