"A matrix 'B' of 5x5 whose elements are all 5"
35 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
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
Respuestas (2)
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.)
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!