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?
Hello, In C#, we are creating a simple calculator that takes two operands and one operator...
Hello, In C#, we are creating a simple calculator that takes two operands and one operator and calculates a result. We need to include a private method to calculate the result as well as try-catch statements for exceptions. My code that i have so far is below, it executes and calculates, but there is an issue with the way i have done the method. Any help or info about my method errors would be great, Thank you! ********************************** using System;...
MATLAB: Matrix M = [ 0 2 3 5; 7 3 8 4 ] Write one...
MATLAB: Matrix M = [ 0 2 3 5; 7 3 8 4 ] Write one command that stores all of the rows of columns 1, 2, and 3 of M into a matrix named M2.
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT