Create array with same number

조회 수: 683 (최근 30일)
Fadal Sasse
Fadal Sasse 2017년 8월 10일
답변: Drue 2023년 2월 22일
I have this command z=ones(length(x),1) If I want to change (ones) with 2 or 3 what I should do?

채택된 답변

James Tursa
James Tursa 2018년 9월 14일
편집: James Tursa 2018년 9월 14일
See this link for a discussion of various methods to do this:
The fastest method seems to be
z = zeros(length(x),1) + 2;

추가 답변 (2개)

José-Luis
José-Luis 2017년 8월 10일
twos = 2.* ones(length(x),1)
  댓글 수: 3
José-Luis
José-Luis 2017년 8월 10일
Please accept the answer that best solves your problem.
PY SUN
PY SUN 2018년 9월 14일
Thanks

댓글을 달려면 로그인하십시오.


Drue
Drue 2023년 2월 22일
To create arrays with the same number I'd personally just set a variable and put it in the linspace function
x = 3
poof = input('how many columns of this number do you want?')
linspace(x,x,poof)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by