Create array with same number

170 ビュー (過去 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 Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by