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 日

6 投票

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 日

19 投票

twos = 2.* ones(length(x),1)

3 件のコメント

Fadal Sasse
Fadal Sasse 2017 年 8 月 10 日
Thanx
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 日

0 投票

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)

カテゴリ

タグ

質問済み:

2017 年 8 月 10 日

回答済み:

2023 年 2 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by