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

Generate 8 × 8 random complex unitary matrix in Matlab. You can only use eig and...
Generate 8 × 8 random complex unitary matrix in Matlab. You can only use eig and randn Matlab functions. Your code can only have two lines and no semicolumns. You should generate a different random unitary matrix with each run.
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.
Again, recall Little’s Law. An escalator can be used two ways: A person can stand and...
Again, recall Little’s Law. An escalator can be used two ways: A person can stand and let the escalator take her to the other end. Or the person can walk the escalator, reaching the other end faster. Suppose by walking a person reaches the other end in 60% of the time she takes just standing. However, when all walk the escalator, they need more space between them to avoid bumping into each other. Thus, the number of persons who can...
MATLAB: Write a function called max_number that takes an at most two-dimensional matrix A as its...
MATLAB: Write a function called max_number that takes an at most two-dimensional matrix A as its sole input. The function returns the largest element of A. You are not allowed to use the built-in max function.
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?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT