Write a function named custom_blocks

3 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2021-12-7
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.

请先登录,再进行评论。

回答(2 个)

Voss
Voss 2021-12-7
function out = custom_blocks(in)
out = [in 2*in; 3*in 4*in];
end
  4 个评论
Walter Roberson
Walter Roberson 2021-12-8
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 2021-12-8
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.

请先登录,再进行评论。


Vaibhav
Vaibhav 2024-6-3
function out = custom_blocks(in)
out = [in 2*in; 3*in 4*in];
end

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by