Untitled

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Format compact command removes the vertical spaces in the result.

Up arrow to go through command history.

Dock command history window by clicking the little down arrow at the top right corner of the window.

You can also drag a command from command history window and drop it in your command window.

This feature is not available in matlab online. There is a tab named command history. Click it to get
entire history. You can’t drag and drop commands here, but you can double click to run a command.

Clc command for clearing the command window, or use clear commands tab to do it.

Search documentation for a command you’re unfamiliar with.

If you want to stop a command that’s taking too long to process, enter Ctrl + C. In online version there’s
a stop button after a command starts executing.

To quit command window there’s the ‘quit’ command.

The rand command (without () it’s not a function, but a keyword or command) generates a random
number between 0 and 1.

To delete variables, enter clear <var name1> <var name2>…. Or right click on the var name in workspace
and click delete. If no var names are given, it’ll clear everything in the workspace. Also, there is the clear
workspace tool to clear all.

By default, var names in workspace are sorted in alphabetical format. But you can change it clicking the
Name header above them.

Tab completion: Type any command halfway and press tab to complete typing it if you used the
command before. Also you can click the command from suggestions popup.

Online: Create a folder in current directory clicking new tab and clicking folder. Double click on the
folder name to make it current.

Installed: 2 ways to create a folder. Right click inside the current directory and select new folder, or you
can click on the little down arrow at the top right corner and click new folder.

Address field: it’s the top bar of the command window and workspace. The right arrows beside each
folder name shows the Childs of the folder upon click. The down arrow at the address bar shows the
recent folders.

The space above the address field is called the tool strip. The tabs within the tool strip can be global
(HOME, PLOTS, APPS): always there, and local (EDITOR, PUBLISH, FILE VERSIONS): appear after new
script is created.

Comments are written with a % sign in the beginning.

Create a new script, save it and run it. Put a function in the script, you can call the function by the name
of the script().
File versions tab saves all the saves that you’ve made to the file. You can go to any saves and also you
can return to latest.

You can recover deleted files in the online version by going to https://drive.matlab.com.

Imshow function takes an image name and displays it.

Upload and download files to and from online version.

Matlab as Calculator
To save your workspace in a file, enter the save command. It’ll save that in a *.mat file and
inform you where that file is located.
The load command loads the workspace variables but doesn’t alter any existing variable.
MATLAB is case sensitive, you can have letter, digits and underscores in your variable name, but
the name must start with a letter. A variable name cannot have more than 63 characters.
Clc stands for clear command window.
You can put multiple command separated by semicolon; semicolon also prevents echo. But you
can use comma as well. Only problem with comma is that it’ll echo. Ex: x = 3, y = 2; will echo x.
Using semicolon instead of comma won’t.
You can put one command in multiple line too. For that you need to put … at the end of each
line except the last. You can’t just break anywhere, only after or before operators.

Syntax and Semantics


Syntax error causes the code not to execute, displays error message in red.
Semantic error will not show any error message, this kind of error occurs due to logical error of
the programmer.

Help
Help command: get more info about any function or command simply by putting the name of
the command after help. I.E., help format
Format loose brings vertical spaces back.
You can also change precision of the output with format long or short.
If you need fancy GUI help you can call doc format, also you can search in documentation in the
search box on top right corner. After you find your desired function name, call help for that
function.
Browse for function button: located at the bottom left corner of the command window (fx), you
can choose the function you want from here as well.
Searching in documentation or browsing for functions are good tools when you don’t know the
name of the function. You can also google it BTW.

Plotting
To plot you need to first define the x and y coordinates.
Docking the plot: click the tiny arrow at the top right corner of the figure so that it won’t go
away when you work.
Plot expects two vectors as input arguments, both same lengths. You can see the length of a
vector with length(vector).
The norm function will give you the square root of the sum of the squares of the vector
elements, what physicists will define as the magnitude of the vector.
Commas can separate commands, function arguments, and elements of a vector. You can
separate the elements of a vector with spaces as well.
The linespec argument is used to tell plot various line styles: colors, types etc. You can add
multiple style specifiers regardless of their order.
Grid on/off command, you know.
Xlabel, ylabel, title functions.
To change the default ranges, use the axis function, it takes a vector of 4 elements: x axis start-
end, y axis start-end. Axis off command to close the axis of the figure.
Bar graphs with bar() function, takes x and y coordinate vectors.
The figure command creates a new figure, and switches focus of next functions to that figure.
Pie chart takes one vector.
Close function takes index of the figure to close. Close all command closes all the figure.
Imread functions creates a matrix from an image file. Don’t forget to put semicolon at the end
to suppress echo.
Image function takes the vector that imread made and displays the picture.

You might also like