Hope this tutorial video is useful for you who would like to learn Matlab and GNU Octave, and please let me know if you have any questions and comments!
(a) Use for-end loops to create a 5*5 matrix in which the value of each element is the difference of its cubic indices (i.e. the cubic row number subtract the cubic column number of the element). For example, the value of element A(3,4) is 3^3 - 4^3 = -37). Show the script file and the result of the matrix A. (b) Use for-end loops and if-end to count (1) how many elements in the above matrix A have the value equal to zero, (2) how many elements in the above matrix A have the positive value, and (3) how many elements in the above matrix A have the negative value. Show the script file and the total number of counted elements in above three cases.
Could you help me to solve part (b) for this problem?: (a) Use for-end loops to create a 5*5 matrix in which the value of each element is the difference of its cubic indices (i.e. the cubic row number subtract the cubic column number of the element). For example, the value of element A(3,4) is 3^3 - 4^3 = -37). Show the script file and the result of the matrix A. (b) Use for-end loops and if-end to count (1) how many elements in the above matrix A have the value equal to zero, (2) how many elements in the above matrix A have the positive value, and (3) how many elements in the above matrix A have the negative value. Show the script file and the total number of counted elements in above three cases.
A couple of different options. 1) use built-in "round function" in Matlab, for example, type "round(pi,2)" to round up the constant "pi" to 2 decimal place. 2) use the built-in function "fprintf", for example, type "fprintf('%.2f ',pi)". Hope this helps.