필터 지우기
필터 지우기

Write a function named custom_blocks

조회 수: 3 (최근 30일)
Siddharth Varshney
Siddharth Varshney 2021년 12월 6일
답변: Vaibhav 2024년 6월 3일
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