Example of vectorizing, MATLAB in Statistics

Example of Vectorizing:

Likewise, for an operation on a matrix, a nested loop would be needed; for illustration, supposing a matrix variable mat:

[r c] = size(mat);

for row = 1:r

for col = 1:c

% do something with mat(row,col)

end

end

typically in MATLAB, this is not essential. The Numerical operations can be completed on whole vectors or matrices. For illustration, let's say that we want to multiply each and every element of a vector v by 3, and store the outcome back in v, here v is initialized as shown below:

>> v = [3 7 2 1];

Posted Date: 10/19/2012 3:53:58 AM | Location : United States







Related Discussions:- Example of vectorizing, Assignment Help, Ask Question on Example of vectorizing, Get Answer, Expert's Help, Example of vectorizing Discussions

Write discussion on Example of vectorizing
Your posts are moderated
Related Questions
Index vector: The index vector is then used as the indices for original vector. To get grades vector in ascending order, the indices used would be grades (2), grades (5), and

Editor/Debugger: The MATLAB has numerous useful functions for debugging, and debugging can also be completed through its editor, which is known as the Editor/Debugger. Typi

Areacirc function: The areacirc function can be called from the Command Window as shown here, or from a script. Here is a script which will prompt the user for the radius of o

Data structure layers: There are many layers in this variable. For illustration,  cyls is the whole data structure, that is a vector of structs  cyls(1) is a separate

Run-time or execution-time error: The Run-time, or execution-time, errors are found whenever a script or function is executing. With most of the languages, an illustration of

Logical errors: The Logical errors are more complicated to locate, as they do not result in any error message. The logical error is a mistake in reasoning by the programmer, b

Example of Mode When no value appears more often than any other, the smallest value in the vector will be the mode of the vector. >> shortx = [2 5 1 4]; >> mode(shortx

WHILE Loops: The while statement is used as a conditional loop in MATLAB; it is used to repeat an action whenever ahead of the time it is not known how many times the action w

Nested Functions: We have seen that the loops can be nested, that means that one inside of the other, functions can be nested. The terminology for nested functions is that an

Execution of persistent variables: The functions can also be called from the script or from the Command Window, as shown here. For illustration, the functions are called first