illustration of nested for loops and the if


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.

Request for Solution File

Ask an Expert for Answer!!
Applications of MATLAB: illustration of nested for loops and the if
Reference No:- TGS0174896

Expected delivery within 24 Hours