Assume that A and B are MATLAB arrays with 10 rows and an equal number...

80.2K

Verified Solution

Question

Electrical Engineering

Assume that A and B are MATLAB arrays with 10 rows and an equal number of columns (the number of columns is not given). Important: Next, the expression \"a single line of code\" implies a single command or equality. In other words, the code:

X=A+1; X=X+B; is considered to be TWO lines of code, even though it can be written as one line.

(a) (3%) Write a single line of code which saves the first two rows of array A as a new array X.

(b) (4%) Write a single line of code which replaces rows 4 and 5 of array A with rows 2 and 6 of array B.

(c) (3%) Write a single line of code which divides all elements in array A by the corresponding elements in array B and saves the resulted array as X.

(d) (4%) Write a single line of code which adds the transpose of array A to array B and saves the result in array X. What should the number of columns of A and B be so that this operation does not result in an error?

(e) (4%) Write a single line of code which uses the MATLAB function \"sum()\" to find the sum of each row

(f) (3%) Lets call N the unknown number of columns of arrays A and B. What is the size of array X = [A B]; ?

(g) (3%) Again, N is the number of columns of arrays A and B. What is the size of array X = [A;B]; ?

(h) (3%) Assume that the arrays A and B have more than 5 columns. Write a single line of code that divides all elements in A by the B element located at row 3 and column 4.

(i) (5%) Write a single line of code using the MATLAB function \"find()\" which finds the location of all elements in A which are greater than 1. Then, write another line of code which replaces all these elements in A by the number 2.

Answer & Explanation Solved by verified expert
4.5 Ratings (1048 Votes)
i A magic10 B A X A12 output A A 92 99 1 8 15 67 74 51 58 40 98 80 7 14 16 73 55 57 64 41 4 81 88 20 22 54 56 63 70 47 85 87 19 21 3 60 62 69 71 28 86 93 25 2 9 61 68 75 52 34 17 24 76 83 90 42 49 26 33 65 23 5 82 89 91 48 30 32 39 66 79 6 13 95 97 29 31 38 45 72 10 12 94 96 78 35 37 44 46 53 11 18 100 77 84 36 43 50 27 59 B B 92 98 4 85 86 17 23 79 10 11 99 80 81 87 93 24 5 6 12 18 1 7 88 19 25 76 82 13 94 100 8 14 20 21 2 83 89 95 96 77 15 16 22 3 9 90    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students