Write a function named custom_blocks
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Walter Roberson
el 7 de Dic. de 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.
Respuestas (2)
Voss
el 7 de Dic. de 2021
function out = custom_blocks(in)
out = [in 2*in; 3*in 4*in];
end
4 comentarios
Walter Roberson
el 8 de Dic. de 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
el 8 de Dic. de 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.
Vaibhav
el 3 de Jun. de 2024
function out = custom_blocks(in)
out = [in 2*in; 3*in 4*in];
end
0 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!