Doing vectorization in the MATLAB

Asked By 20 points N/A Posted on -

Hi friends

How do i do vectorization in the MATLAB? 

How do i import MATLAB graphics into my Framemaker?


Best Answer by Sharath Reddy
Answered By 0 points N/A #109308

Doing vectorization in the MATLAB


Manipulation of vectors in Matlab is very easy because its language was designed in Linear Algebra Notation. The first thing when you start Matlab is to enter your commands, vectors are so common is Matlab commands and are defined by placing a sequence of numbers within square braces, for example: v = [3 1] and in case you want to print the vector v, all you need is to type its name.

The above command will create a vector with two variables; the first entry being a 3 and the second a 1. The print command in Matlab gives you a “-deps” argument which provides an Encapsulated PostScript file of your plot. Most people experience problems here but this could be of help to you: You must delete the last line "%%EOF" from the eps-file and try the pstoepsi filter. Make sure to use "bbps" and ghostscript. "bbps.shar" is available via anonymous ftp on "". You will need to get GhostScript from your nearest GNU ftp site.
Best Answer
Best Answer
Answered By 572870 points N/A #109309

Doing vectorization in the MATLAB


Vectorization is the manner of altering scalar-oriented, loop-based code to use MATLAB vector and matrix operations. MATLAB is optimized for processes concerning vectors and matrices. There are numerous reasons why it is useful to vectorize your code:

  • Less error prone – frequently vectorized code is shorter because it doesn’t have loops. The lesser the lines of codes are the lesser the chance of getting programming errors.
  • Appearance – mathematical codes that are vectorized seems more similar to mathematical expressions obtained on textbooks. This way the code can be understood more easily.​
  • Performance – frequently vectorized code runs greatly faster than the equivalent code that has loops.

Below is an example of a code that calculates the sine of 1,001 values ranging from 0 – 10.

This is the standard code that contains loops and has not been vectorized yet.

Applying vectorization to the code above will result to this:

t = 0:.01:10;
y = sin(t);

The second code normally runs faster compared to the first one.

This is a more effective use of MATLAB.

Login/Register to Answer

Related Questions