"A matrix 'B' of 5x5 whose elements are all 5"

35 visualizaciones (últimos 30 días)
Gabriel
Gabriel el 31 de Ag. de 2022
Comentada: Walter Roberson el 31 de Ag. de 2022
My current 'correct' solution to this problem is:
B = [5,5,5,5,5;5,5,5,5,5;5,5,5,5,5;5,5,5,5,5;5,5,5,5,5;]
But this seems a little long and silly. Is there an identity matrix like "M = ones[2,3]" that works for this application?
  1 comentario
Walter Roberson
Walter Roberson el 31 de Ag. de 2022
https://www.mathworks.com/matlabcentral/answers/87577-how-do-i-create-a-10-10-matrix-containing-numbers-from-1-to-100#comment_2335570 I gave 5 answers

Iniciar sesión para comentar.

Respuestas (2)

John D'Errico
John D'Errico el 31 de Ag. de 2022
Can you create a matrix of the desired size that is all ones? (Clearly yes, since you know how to use the ones function.) Could you then multiply all elements of that matrix by the number 5? (I hope so.)
As an alternative, could you use the repmat function? (Of course.)

Torsten
Torsten el 31 de Ag. de 2022
B = 5*ones(5)
B = 5×5
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by