Is there a function to make a long list of a single value?

1 次查看(过去 30 天)
I.e. if I want to make a list 400 values long of all 1's, I would use
ones(400,1)
But what if I wanted to make a list of say, 5's?
Is there a function I can use to do this without using a for loop?

采纳的回答

Star Strider
Star Strider 2022-5-24
Try this —
Fives = 5*ones(400,1)
Fives = 400×1
5 5 5 5 5 5 5 5 5 5
.
  2 个评论
Star Strider
Star Strider 2022-5-24
Thank you!
I’m certain you would have in a few minutes. (I’ve been doing this for a while.)
Another option —
Fives = 5+zeros(400,1)
Fives = 400×1
5 5 5 5 5 5 5 5 5 5
.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by