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

Data structure layers, Data structure layers: There are many layers in...

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 sorting strings, Example of sorting strings: To sort a cell...

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',.

Function sortrows - sorting strings, function sortrows - sorting strings: ...

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

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

Nested functions, Nested Functions: We have seen that the loops can be...

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

Editor and debugger, Editor/Debugger: The MATLAB has numerous useful f...

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

Steps for input output functions - lower level file, Steps for input output...

Steps for input output functions - Lower level file: The steps involved are as shown below:  Open the file.  Read the file, write to the file, or append to the file.

Opening and closing a file, Opening and Closing a File: The Files are ...

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

Fopen function - file function, fopen function - file function: The fo...

fopen function - file function: The fopen opens the file for reading. The fscanf then reads each line one double and one character, and put each pair in individual columns in

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