Create array with same number

576 次查看(过去 30 天)
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)

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