How to Create a 5x5 matrix whose rows are (1:5)?

15 views (last 30 days)
Create a 5x5 matrix whose rows are (1:5).

Accepted Answer

Star Strider
Star Strider on 6 Sep 2017
You can do that with simple vector multiplication:
A = ones(5, 1) * (1:5);

More Answers (1)

KL
KL on 6 Sep 2017
Edited: KL on 6 Sep 2017
A = repmat(1:5,5,1);
or in general,
N = 5;
A = repmat(1:N,N,1)

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!