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

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

Example of Median For the vector [1 4 5 9 12 33], the median is the average of the 5 & 9 in the middle: >> median([1 4 5 9 12 33]) ans =     7

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

#qYou will need to examine two of the nine sections of data: one section of qualitative data (choose either Gender or Position) one section of quantitative data (choose either Intr

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

Introduction and Purpose In the lectures and tutorials you have been introduced to a number of probability distributions. You have also learned that modelling any system (such

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