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]

回答(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 个评论

we don't have to type individual element explicitly.
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...

请先登录,再进行评论。

类别

在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

提问:

2016-8-11

评论:

2016-8-11

Community Treasure Hunt

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

Start Hunting!

Translated by