## 20 MATLAB commands you won't forget

**clc**clear the command window.*Probably the best command of all time to reduce user anxiety.***clear all**clear all variables in your workspace.*Trust me you'll be using this one.***plot()**Plot curves by inserting vectors of the same length in the function.*Amazing.***subplot()**Plot multiple figures in one window.*Godlike.***axis([**-1 1 -1 1**])**Set the minimum x and y axis of your plot.*This can be set manually too.***legend('**string**')**Name the data series of your figure.*Pretty sweet!***shg**Display the figure window instantaneously.*No more frustrating clicks!***run**directory/scriptnameRun another script within your script.*Helps you keep it clean and organised.***load**directory/workspacefileLoad variables saved from the workspace directly to your script.**help**functionAccess the documentation on the usage of the function directly in your command window.*This is the command I use the most in MATLAB by far!***length(**vector**)**Returns the length of a vector.*Very useful when using for loops.***size(**matrix**)**Returns the size of a matrix.*First thing I do when I get dimensioning error messages!***ones()**Create a vector or a matrix of ones.*This is awesome, forget building a vector like this: x=[1 1 1 1 1], just use ones(1,5) and you'r good.***zeros()**Creates a vector or a matrix of zeros.*Same principle here but with zeros!***rand()**Create a random vector or a matrix.*So convenient when you'r just goofing around or testing basic things.***disp('**string**')**Display a string in the command window.**tic**Start the invisible stopwatch.**toc**Stop the stopwatch and get information on the time elapsed!*Useful if you want to know the duration of a simulation for example!***input()**Prompt the user for an input.*Can be very useful when using if conditions.***xlsread(**directory/filename,sheet,range**)**Read a range of data from an excel sheet.*Gaaah, this is for all of you who like me, thinks Excel is good for sorting data but terrible for presenting figures.*

I hope you will find these commands helpful! There are tons of them out there and I do encourage you to take a look at the online documentation or just google some on your spare time. The more commands you learn the faster and more elegantly will you be able to solve your future homework assignments!

http://www.mathworks.se/help/matlab/

## Comments

You need a Ludu account in order to ask the instructor a question or post a comment.

Be the first to comment!