Lesson 4

Useful MATLAB commands


20 MATLAB commands you won't forget

  1. clcclear the command window. Probably the best command of all time to reduce user anxiety.

  2. clear allclear all variables in your workspace. Trust me you'll be using this one.

  3. plot()Plot curves by inserting vectors of the same length in the function. Amazing.

  4. subplot()Plot multiple figures in one window. Godlike.

  5. axis([-1 1 -1 1])Set the minimum x and y axis of your plot. This can be set manually too.

  6. legend('string')Name the data series of your figure. Pretty sweet!

  7. shgDisplay the figure window instantaneously. No more frustrating clicks!

  8. run directory/scriptnameRun another script within your script. Helps you keep it clean and organised.

  9. load directory/workspacefileLoad variables saved from the workspace directly to your script.

  10. 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!

  11. length(vector)Returns the length of a vector. Very useful when using for loops.

  12. size(matrix)Returns the size of a matrix. First thing I do when I get dimensioning error messages!

  13. 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.

  14. zeros()Creates a vector or a matrix of zeros. Same principle here but with zeros!

  15. rand()Create a random vector or a matrix. So convenient when you'r just goofing around or testing basic things.

  16. disp('string')Display a string in the command window.

  17. ticStart the invisible stopwatch.

  18. tocStop the stopwatch and get information on the time elapsed! Useful if you want to know the duration of a simulation for example!

  19. input()Prompt the user for an input. Can be very useful when using if conditions.

  20. 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!




Be the first to comment!