I noticed that there is a lack of MATLAB related posts so I figured I'd add some things to help people who are starting out with the MATLAB technical language.
First and foremost, the two most useful functions for a beginner to MATLAB are help and doc. These keywords allow the user to basically search the huge database for proper syntax, use and related functions for any of the built-in functions in MATLAB's library.
help plot help max doc sin doc numel
As you probably know, MATLAB uses what is referred to as vectorization, meaning that in most cases, the fastest and most efficient method for accomplishing a task is to use MATLAB's highly optimized functions instead of writing our own. Basically, when using MATLAB, our task is to write "brace" code that serves as the foundation for incorporating these functions into our own code to accomplish unique tasks. This is why the help and doc keywords are so useful; make sure you're not trying to rewrite functions that already exist in MATLAB's library! With this said, I will jump into the fundamentals of vector/array and matrix creation and manipulation.
Similarly to languages such as C++/C, MATLAB takes advantage of vectors and arrays.
Techniques for vector creation:
//Simple "brute force" data entry: v = [1,2,3,4,5] // Creates vector (v) with numbers 1 through 5 (comma can be replaced with a space). //More efficient use of the "colon operator": v = [1:5] // Creates vector (v) with numbers 1 through 5, default increments set to 1. // Colon Operator Continued: v = [0:2:12] //Creates vector (v) with numbers 0 to 12 in increments of 2. // linspace function: linspace(0,12,2) // Same as colon operator above, but with direct control over increments. //Create a matrix v = [1 2 3 4 5; 6 7 8 9 10] // Where; indicates a new row v = [1:5; 6:10] // Use colon operator v = ones(5) //Creates a 5x5 matrix of 1s v = eye(5) //Creates a 5x5 identity matrix v = zeros(5) //Creates a 5x5 matrix of 0s
Ok, so those are the very basics of vector and matrix creation in MATLAB. As you can imagine, with the creation of matrices in MATLAB you can do a whole host of operations with simple built in functions such as min() max() plot() etc. Thats all for now, but I plan on posting another mini tutorial on indexing using the colon operator as well as appending and updating data in matrices/vectors.