Illustration of nested for loops and the if statements, MATLAB in Statistics

Illustration of nested for loops and the if statements:

For illustration,when the file contains:

33   -11  2

 4      5   9

22     5  -7

 2     11    3

the outcome from the program would look like this:

>> sumonlypos

The sum for row 1 is 35

The sum for row 2 is 18

The sum for row 3 is 27

The sum for row 4 is 16

 

The file is loaded into matrix variable. The script finds the size of the matrix and then loops through all the elements in the matrix using a nested loop; the outer loop iterates through the rows and the inner loop iterates through the columns. For each and every element, an if-else statement determines whether the element is positive or not. It adds only the positive values to the row sum. As the sum is found for each and every row, the sumrow variable is initialized to 0 for every row; it means that inside the outer loop.

Posted Date: 10/19/2012 3:52:47 AM | Location : United States







Related Discussions:- Illustration of nested for loops and the if statements, Assignment Help, Ask Question on Illustration of nested for loops and the if statements, Get Answer, Expert's Help, Illustration of nested for loops and the if statements Discussions

Write discussion on Illustration of nested for loops and the if statements
Your posts are moderated
Related Questions
Median The median is defined only for a data set which has been sorted first, that means that the values are in order. The median of a sorted set of data values (n) is defined

Curve Fitting: The data is fundamentally either discrete or continuous. In most of the applications, data is sampled, for illustration, The temperature recorded every ho

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

Illustration of Median When the vector is not in sorted order to start with, the median function will still return the right answer (it will sort the vector automatically). For

Advanced File Input and Output: In that section, we saw how to read the values entered by user using the input as well as the output functions disp and fprintf, that shows inf

Example of Functions which complete a task: For illustration, the function below just prints the number arguments passed to it in a sentence format: As this function i

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

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

Rectangle - graphics objects: The other core graphics object is the rectangle that can have curvature added to it (!!). Merely calling the function rectangle without any argum

Determine sequence weights for the sequences ACTA, ACTT, CGTT, and AGAT in problem 1 by using Thompson, Higgins, and Gibson method a) compute pairwise distances between sequences