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

Assignment Help:

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.


Related Discussions:- Illustration of nested for loops and the if statements

Combining nested for loops and the if statements, Combining Nested FOR Loop...

Combining Nested FOR Loops and the IF Statements: The statements inside a nested loop can be any of the valid statement, involving any selection statement. For e.g., there can

Statistics, Statistics There are numerous statistical analyses which ca...

Statistics There are numerous statistical analyses which can be executed on data sets. In MATLAB software, the statistical functions are in the data analysis help topic known a

Menu function, MENU Function: The MATLAB also has a built-in function ...

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

Median, Median The median is defined only for a data set which has been...

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

Areacirc function, Areacirc function: The areacirc function can be cal...

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

Nested structures, Nested Structures: The nested structure is a struct...

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

Illustration of customizing plots, Illustration of Customizing plots: ...

Illustration of Customizing plots: Illustration, the bar and barh functions by the default place a width of 0.8 between bars. Whenever called as bar(x,y), the width of 0.8 is

Example of median, Example of Median For the vector [1 4 5 9 12 33], th...

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

Curve fitting, Curve Fitting: The data is fundamentally either discret...

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

Lower level file i/o functions, Lower Level File I/O Functions: Whenev...

Lower Level File I/O Functions: Whenever reading from data file, as long as the data in the file is "regular" the load function works-in another words, the similar type of dat

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd