Hide menu

TDDD34 Programming with Applications in Engineering

Getting started


To start the work with Matlab and the laborations you need to know a little bit about the environment and the tools. You should have learned all about this in the STONE material, but some the steps you need to get going on the labs are nevertheless given here.

Open a terminal

You can just right-click on the desktop and select "Open terminal", or you can open the "start" menu (bottom left) and select "Program -> Tools -> Terminal".

Structure the work

Course folder

It is good to keep all work related to one course in one folder. You can create this folder by issuing this command in the terminal:

mkdir TDDD34

Change folder

Move to the newly created folder. In the terminal you do this by the command "cd". To move to a folder located inside the folder you are currently in, you just append the name of that folder to the "cd" command. In this case:

cd TDDD34

If you want to move straight to the folder no matter the current one, you write:

cd ~/TDDD34

The above assume the folder TDDD34 resides in your home folder (~).

Lab folders

Once you are inside the TDDD34 folder it suitable to create one "work" folder for each laboration, to easier keep track of all the files you will create later (it will be quite a few). Create a folder for the first lab and change to it:

mkdir lab-1
cd lab-1

The above two commands assume you are in the ~/TDDD34 folder created previously. To find out which folder you are in you can type the command:

pwd

To move directly to the "lab-1" folder on a later occasion you can use the "cd" command with the full path:

cd ~/TDDD34/lab-1

This will move from your home folder ("~") to "TDDD34" and on to "lab-1" in one step. Observe that this of course only affect the terminal (command line) you used.

In the TDDD34 folder, create one folder for each lab.

Miscellaneous files

On the course homepage you can find any files related to a particular laboration. Copy them to suitable folder. You can do it now or when you reach the laboration that refer to them.

Writing programs

To write programs you need an editor. Emacs is unprecedented (refer to STONE) but in this case you may choose you to use the Matlab built-in editor. It is easier for the novice to get used to, and still have some features simplifying writing Matlab programs (such as pressing Ctrl-I to indent the code). To start the Matlab built-in editor you must first start Matlab.

BEFORE starting Matlab the first time (ONLY ONCE)

When you at first log on to the computers at IDA, the environment is not configured for you to run Matlab. Fortunately it is very simple to do the configuration, and automate it for the next log on. In the terminal, do the following:

module add prog/matlab
module initadd prog/matlab

The first command enable Matlab in the current terminal "this time only". The second tells the system to enable Matlab automatically for you in the future, whenever you log on and start a terminal.

Starting Matlab subsequent times

Before you start Matlab you should "cd" to the folder you intend to work in (you can do this in the Matlab command line too, if you forget). Then you are prepared to start Matlab:

cd ~/TDDD34/lab-1
matlab &

If you are curios about the final "&" sign, it instructs the terminal that you want to issue more commands in the terminal before Matlab exits. If you forget it the terminal become unavailable until Matlab finish (there is a way to fix, ask your supervisor).

If everything works, after some time, a Matlab window will pop up. To make Matlab appear faster you can start Matlab without all graphics and use emacs as editor:

cd ~/TDDD34/lab-1
emacs &
matlab -nosplash -nodesktop

Matlab will now start inside your terminal (command line). This enable the experienced to work more efficient, but you need some practice to get the experience.

First time in Matlab

This assume you use the graphical interface and Matlab 7.4.0 (R2007a). Other versions may look slightly different, but the core concepts are the same, and you are a thinking human being, you can figure out the differences. Once Matlab is open you will see something similar to this window:

The window is split in threw views, or subwindows. You will also find a large collection of buttons. You can figure out what all the buttons are for on your own, or ask your supervisor.

Directory window

The top left window show the content of the current directory (folder). You can click to navigate and open files.

Command window

The right large window is the most important window. It is the command window. All the power of Matlab is in this window, and that is what you will use for "experimentation". You write help on an command, and then you can try the command with different data to figure out how to use it before you include it in your programs. Of course, you also use it to execute your window.

History window

The bottom left window is finally the history window. It contains a list of all commands you executed in the command window. You can conveniently access any old command again.

Starting the editor

To start the built-in editor you exercise the power of the command window. Simply write "edit" and confirm with enter. You may optionally add a filename after edit in which case that file will be opened or created. A window like this will appear:

Docking the editor

It is however not convenient to have several windows on top of each other. It is more convenient to organize the windows side by side. This is what the "docking" feature does. Look in the Desktop menu in the editor window and select "dock editor".

It will seamlessly integrate itself with the rest of the windows. The only drawback is that the powerful command window gets smaller.

Commands in Matlab

You can do almost any calculations and plots in Matlab, refer to the cribs in the material section in for information on some of the most common commands available.

Preparing to the exam

It is of utmost importance that you understand and try how all different commands work in Matlab. Experiment with them. Try this and that to figure out how it works. Use the "help" command in Matlab to get a description of what a command do. This will increase you chances to pass the exam be flying colors. Be curious and explore. The exam will be done on the same computers as the labs, using the same tools. Be sure to learn everything you possibly can about them. Be sure to grab the keyboard from you friend every now and then.


Page responsible: Erik Nilsson
Last updated: 2012-08-07