198

The MATLAB Interface / Integrated Development Environment (IDE)


Article posted on Thursday, 23rd, February, 2012 at 3:32 pm


Okay, so starting up MATLAB for the first time might make you think ‘Woah, this is it? This is what everyone’s been raving about? What’s so special about it?’. Well, let me spend a little time showing you how to set it up and get you up and running with it…

The first thing you’ll generally see when starting MATALB for the first time is a screen like this:

The MATLAB IDE

Now, before you get familiar with this setup, I advise that you immediately go to the menubar at the top and go to Desktop > Editor. This will create a floating window – within which, you should click the little downward pointing arrow in the top right to dock it to your IDE:

Dock the Text Editor to your IDE

Once clicked, you’ll be able to see MATLAB in all it’s potential glory! Now, look at the labelled image below to get an idea of what you’re looking at:

The MATLAB IDE with labelled panels

Looks pretty easy huh? Lets test it out!

I’m going to make a variable called “greeting”. This will be a string with the characters ‘hello there!’ in (excluding quotes). To do this in MATLAB, type:

greeting = 'hello there!';

into the command window (bottom middle one in the above picture). Now hit enter – do you see what has changed? In your variable viewing pane, or ‘workspace’, it is listing that variable as being stored in memory. If you double click on it, you can examine it further. The command you just executed also appeared in the command history pane. this is useful if you want to keep repeating the same commands / set of commands – just select and hit enter / double click / whatever!

Note the semicolon in the line of code. This suppresses command line output. If you were to type it without the semicolon, it would display what that line of code has resulted in. In this case a variable being created with the string ‘hello there!’. Give it a try!

Now, what if you wanted to write this as a script that you could save and run as and when you liked? Simple! Just type it in the editor and hit the save icon. Save it in the current directory and you’ll see the .m file appear in the top left pane, which is for listing files and folders in your present working directory (in my case, C:\…\Documents\MATLAB).

To run your new script, you can press F5 or click the green play button icon. If you have the semicolon there, you won’t see anything happen, so lets make our program a tiny bit longer:

% -- In MATLAB - anything after a percent sign is a comment --
% This program assigns a greeting message to a string variable
% and then outputs the string variable to the command window

greeting = 'hello there!'; 
disp(greeting)

Now we are creating the variable and using that variable with the disp function to display it. Notice al the lovely text colouring now that you’re using the editor. The comments should be green, and the string should be pink/purple. Note that it doesn’t matter about the semicolon when using disp, because you want it to output to the command window!



Tags: , , , , , ,

Join in the Conversation


comments powered by Disqus