Question: Problem 4 Nested for-loops, function, if-statement Write a function table mult to make a multiplication table of size NxN as shown below, for an input

 Problem 4 Nested for-loops, function, if-statement Write a function table mult

Problem 4 Nested for-loops, function, if-statement Write a function table mult to make a "multiplication table" of size NxN as shown below, for an input value of table size, N. The function will return a matrix with values as shown in the tablee You may assume N to be a positive integer. . >> A = table mult(5) 12 15 16 20 10 25 >> B = table mult (1) Meaning: In the example above A(3,2) has value of 6-3x2, (at row 3 and column 2) The 3rd row, [3, 6, 9, 0, 0] corresponds to [3x1, 3x2, 3x3], while 3x4 and 3x5 are not "shown" (leave as zeros), since they can be seen from 4x3 and 5x3 o Hints: o Create the final output matrix as all zeros first. o Use 2 for-loops. One for iterating row number, the other for iterating columin number. Use an if-statement to select whether to overwrite a zero with a new value Note that we only need to overwrite elements with its row number greater or equal to its column number. However, it is also possible to set up the inner for-loop in such a way that an if-statement is not needed Pre-allocation of memory is optional, but you should try to do it. o o Example of a matrix with some pattern, generated by using nested for-loops: A = zeros (4,4) for r=1:4 12 13 23 14 24 3 4 for c = 1:4 if (r

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!