Lecture23 For_Loop_II

Tutorial:
 

 

     

 



T_data.xls can be downloaded here
   

   

Tasks:
1. Use a For Loop to calculate the summation of [2 5 6 7 8 8 10 11];
2. Count how many positive numbers are in matrix [4 5 6 7 8 -2 -1 0]; Calculate the average of the positive numbers.
3. Use a For loop to find the maximum value in [4 5 3 2 32 33 45 1 2 ];
4. Use nested For Loops to find the number of negative values in [1 2 3; -3 4 5; 9 -5 3]. (May need two counters)
5. Use a ‘For Loop’ to compute the summation and the average of this vector: A1=[2 3 4 9 10 34].
6. Use a ‘For Loop’ and the ‘If Statement’ to compute the average of the non-negative numbers in a vector: A2=[-5 2 4 -1 6].
7. Extract the positive elements of A3
=[8 -4 -5 3 0 1] into a new array A4.
8. Find the first negative value in a data set and then quit the loop. A5=[1 3 0 8 -5 3 0 1 -9].