Question

In: Computer Science

8. In MATLAB, the colon operator can be used in two ways: creating a matrix (or...

8. In MATLAB, the colon operator can be used in two ways: creating a matrix (or array) and selecting part(s) of a matrix (or array). Explain and give examples of each.

9. For a matrix C, that has 10 rows and 12 columns:

- What is the MATLAB command to select all of row 5 from it?

- What 2 MATLAB commands would ask the user for an integer, N, from 1 to 10 and then create an array D which is just row N from matrix C?

10. For matrix D, that has 5 rows and 8 columns:

- What does the MATLAB command Z=sum(D) do and what is the size (or dimensions) of Z?

Solutions

Expert Solution

(8)   
   In Matlab, colon operator can be used in two ways:
  
   Way 1:   Creating a matrix(or array)
  
      
       1.   Statement a:b creates a vector from a to b.
       2.   Statement a:k:b creates a vector from a to b at an increment of k
      
   Example:   Creating a matrix of dimension 3x5

      >> m = [1:5 ; 6:10 ; 11:15]
       m =

          1    2    3    4    5
           6    7    8    9   10
           11   12   13   14   15

       >>
      
      
   Way 2:   Selecting parts of array

      mat(:,j)   ->   Returns j th column.
       mat(i,:)    ->   Returns i th row.
       mat(:,:)    ->   Returns entire matrix.
      
       >> m(:,:)
       ans =

           1    2    3    4    5
           6    7    8    9   10
           11   12   13   14   15

       >>
       >> m(1,:)
       ans =

       1   2   3   4   5

       >> m(:,4)
       ans =

       4
       9
       14

_____________________________________________________________________________________________________________________

(9)
   Creating a sample matrix C, that has 10 rows and 12 columns:
  

   >> C = randi(10,10,12);
  
  
   MATLAB command to select all of row 5 from it:
  
   C(5,:)
  

   Fetches entire fifth row
  
   Two MATLAB commands would ask the user for an integer, N, from 1 to 10 and then create an array D which is just row N from matrix C:
  
   Asking user for integer N:
  

   N = input(' Enter N value (1 to 10) : ');
  

   Creating an array D which is just row N from matrix C:
  

   D = C(N,:)

_____________________________________________________________________________________________________________________

(10)
  
   Creating a sample matrix D, that has 5 rows and 8 columns:
  

   >> D = randi(10,5,8);
  

   Command Z=sum(D); calculates sum of each column values in array D and stores the result as column in Z.
  
   Size (or dimension) of Z can be found using command size(Z); which returns 1 row and 8 columns.
   


Related Solutions

8. What are 3 ways in that CVP analysis can be used by managers to make...
8. What are 3 ways in that CVP analysis can be used by managers to make decisions?
Identify the ways in which credit can best be used.
Identify the ways in which credit can best be used.
Permutations 1) In how many ways can 8 identical rooks be placed on an 8×8 chessboard...
Permutations 1) In how many ways can 8 identical rooks be placed on an 8×8 chessboard so that none can capture any other, namely no row and no column contains more than one rook? 2) In how many ways can three couples be seated in a row so that each couple sits together (namely next to each other): a) Row b) In a circle
If v is an eigenvector for a matrix A, can v be associated with two different...
If v is an eigenvector for a matrix A, can v be associated with two different eigenvalues? Prove your answer.
Describe two ways in which psychological factors can contribute to depression. Describe two ways in which...
Describe two ways in which psychological factors can contribute to depression. Describe two ways in which biological influences can lead to depression. describe three different treatment options for depression. Name the characteristics of each of the three types of bipolar disorder. What is a key treatment for bipolar disorder?
In how many ways can an 8×8 chessboard be tiled with dominoes? Ex-plain your answer.
In how many ways can an 8×8 chessboard be tiled with dominoes? Ex-plain your answer.
4. How many different ways can you put 8 balls in 8 boxes A1, . ....
4. How many different ways can you put 8 balls in 8 boxes A1, . . . , A8 if (a) the balls are all different and no box is empty 8! (b) the balls are all different and only three boxes A1, A2 and A3 are empty (c) the balls are all different and exactly four boxes are empty (d) the balls are all different and each box is either empty or contains exactly two balls (e) the balls...
5. The structure of a two-way ANOVA study can be presented as a matrix with the...
5. The structure of a two-way ANOVA study can be presented as a matrix with the levels of one factor determining the rows and the levels of the second factor determining the columns. Factor A A1                                                           A2                                        B1 Factor B                                                                 B2 Factor A A1                                                           A2                                        B1 Factor B                                                                 B2 a. What are the three hypotheses that are evaluated in this study? b. With this structure in mind, describe the mean differences that are evaluated by each...
The results from a two-factor experiment can be presented in a matrix with the levels of...
The results from a two-factor experiment can be presented in a matrix with the levels of one factor forming the rows and the levels of the second factor forming the columns, with a separate sample in each of the matrix cells. Demonstrate this with your own example, and describe what is meant by the main effects for each factor and the interaction between factors based on the numbers that you choose to plug in for each one of the cells.
. There are ba (= 14) ways to arrange 1, 2, 3, ..., 8 in two...
. There are ba (= 14) ways to arrange 1, 2, 3, ..., 8 in two rows of four so that (1) the integers increase in value as each row is read, from left to right, and (2) in any column the smaller integer is on top. Find, as in part (d) of Example 1.43, a) the arrangements that correspond to each of the fol- lowing. 1) 10110010 i) 11001010 lli) 11101000 b) the lists of four l's and four...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT