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
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

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

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

Example of Core objects: The one core graphics object is a line that is also what the plot function produces. Here is an illustration of generating a line object, altering som

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

function sortrows - sorting strings: The function sortrows sorts each and every row as a block, or group, and it also will work on numbers. Here in this illustration the rows

Graphics objects: The objects involve graphics primitives like lines and text, and also the axes used to orient the objects. These objects are organized hierarchically, and the

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

Opening and Closing a File: The Files are opened with the fopen function. By the default, fopen function opens a file for reading. If the other mode is preferred, a permission

Example of sorting strings: To sort a cell array of strings, also the sort function is used. The illustration is as follows, >> engcellnames = {'Chemical','Mechanical',.