Create array with same number

I have this command z=ones(length(x),1) If I want to change (ones) with 2 or 3 what I should do?

 采纳的回答

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 个)

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)

类别

帮助中心File Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by