Page 1 of 1

Beginner MATLAB Tutorial P.1. Basic Introduction to 1D Arrays and Matrices

#1 InfiniteL00P  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 12
  • Joined: 05-November 09

Post icon  Posted 05 November 2009 - 08:19 PM

Hello Dream.In.Code,
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.

Is This A Good Question/Topic? 1
  • +

Replies To: Beginner MATLAB Tutorial P.1.

#2 wartech  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 203
  • Joined: 16-October 06

Posted 13 May 2010 - 09:41 PM

Thanks InfiniteLOOP. I will be taking Linear Algebra with Apps this summer and need all the info I can find on MATLAB.
Was This Post Helpful? 0
  • +
  • -

#3 Christos75  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 55
  • Joined: 06-October 09

Posted 26 November 2010 - 12:19 AM

Really useful,thank you!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1