how to create a matrix in sigle command?

single command to create this matrix c = [0 0 0 0 0;0 0 1 2 3;0 0 4 5 6;0 0 7 8 9]

Answers (1)

One single command:
c = [0 0 0 0 0;0 0 1 2 3;0 0 4 5 6;0 0 7 8 9];
Best wishes
Torsten.

4 Comments

we don't have to type individual element explicitly.
Torsten
Torsten on 11 Aug 2016
Edited: Torsten on 11 Aug 2016
Why ? I think it's most clear if you define the matrix explicitly (at least if it's only 4x5 and quite difficult in its structure).
Best wishes
Torsten.
Yes, you won't find any simpler or faster than just typing the numbers. Otherwise, you have to concatenate bits of matrices to obtain what you want:
c = [zeros(4, 3), [zeros(1, 3); reshape(1:9, 3, 3)']];
Not any clearer, and certainly slower!
Thanks, It was an assignment given to me. Thanks for your help...

Sign in to comment.

Categories

Asked:

on 11 Aug 2016

Commented:

on 11 Aug 2016

Community Treasure Hunt

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

Start Hunting!