Write a function named custom_blocks

7 Ansichten (letzte 30 Tage)
Siddharth Varshney
Siddharth Varshney am 6 Dez. 2021
Kommentiert: Stephen23 am 10 Dez. 2021
Write a function named custom_blocks that takes an n-by-m
matrix as an input argument (the function does not have to check the format
of the input) and returns a 2n-by-2m matrix as an output argument. The upper
left n-by-m sub matrix of the output matrix is the same as the input matrix.
The elements of the upper right n-by-m sub matrix are twice as large as
the corresponding elements of the input matrix. Similarly, the lower left submatrix
is the input matrix multiplied by three and the lower right n-by-m submatrix
is four times the input matrix. For example, here is an example run:
>> custom_blocks([1:3;3:-1:1])
ans =
1 2 3 2 4 6
3 2 1 6 4 2
3 6 9 4 8 12
9 6 3 12 8 4
  9 Kommentare
Walter Roberson
Walter Roberson am 7 Dez. 2021
The problem does not pass in the values of m and n . The problem passes in a matrix with a particular number of rows and a particular number of columns. If you call the number of rows received n, and the number of columns received m, then the number of rows out must be 2*n and the number of columns out must be 2*m -- that is, the output must have twice as many rows as the input, and twice as many columns as the input.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Voss
Voss am 7 Dez. 2021
function out = custom_blocks(in)
out = [in 2*in; 3*in 4*in];
end
  4 Kommentare
Walter Roberson
Walter Roberson am 8 Dez. 2021
The experience of the long-time volunteers is that it is most often better to guide students into how to read questions, and how to find resources, rather than to give them exact solutions to problems. In cases where specific code is useful, it is our experience that is often better to give code for a different question that uses the same principles, so that the student at least has to recognize the principles.
Voss
Voss am 8 Dez. 2021
I appreciate your comments. In the future, I will take the approach of solving a similar question that uses the same principles, as you suggest.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by