Need of a nested loop, MATLAB in Statistics

Need of a nested loop:

How would we sum each individual column, rather than getting an overall sum?

Answer:

The programming technique would need a nested loop in which the outer loop is over the columns. For illustration, we will modify the earlier function to sum each column and return a row vector containing the results.

408_Need of a nested loop.png

2287_Need of a nested loop1.png

Note: The output argument will be a row vector containing similar number of columns as the input argument matrix

Also, as the function is computing a sum for each column the runsum variable should be initialized to 0 for every column. Therefore it is initialized inside of the outer loop.

 

>> mat = [3:5; 2 5 7]

mat =

    3   4   5

    2   5   7

 

>> matcolsum(mat)

ans =

    5   9   12

Obviously, the built-in sum function in a MATLAB would accomplish similar thing.

Posted Date: 10/19/2012 3:49:36 AM | Location : United States







Related Discussions:- Need of a nested loop, Assignment Help, Ask Question on Need of a nested loop, Get Answer, Expert's Help, Need of a nested loop Discussions

Write discussion on Need of a nested loop
Your posts are moderated
Related Questions
bjjh

Illustration of Binary search: An illustration to search for the key of 91 in the vector is as shown below: The table below shows what will happen in each iteration of

Persistent Variables: Generally, whenever a function stops executing, then the local variables from that function are cleared. That means that each and every time a function i

MENU Function: The MATLAB also has a built-in function known as menu which will display a figure Window with push buttons for the choices. The very first string passed to the

Vectors of nested structures: The Combining vectors and nested structures are possible to have a vector of structures in which several fields are structures themselves. Here i

Program of Persistent variables: The program below elaborates this. The script calls a function func1 that initializes a variable count to 0, then increment it, and print the

Use of function polyval: The better the curve fit, the more exact these interpolated and extrapolated values will be. By using the subplot function, we can loop to display the

Nested Structures: The nested structure is a structure in which at least one of the members is itself a structure. For illustration, a structure for the line segment may co

Variable packages: Variable packages are now the vector of structures, hence each and every element in the vector is a structure. To show one element in the vector, an index i

Representing Logical true and False: It has been stated that expressions which are theoretically true really have the integer value of 1, and expressions which are theoretical