필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
David Haydock
David Haydock 2022년 5월 24일
댓글: Star Strider 2022년 5월 24일
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
David Haydock
David Haydock 2022년 5월 24일
You're a genius! Why didn't I think of that!
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