"A matrix 'B' of 5x5 whose elements are all 5"
Show older comments
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 Comment
Walter Roberson
on 31 Aug 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
Answers (2)
John D'Errico
on 31 Aug 2022
3 votes
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.)
B = 5*ones(5)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!