Custom Vector - make vector x to be [1,1,....]

1 次查看(过去 30 天)
Hello Experts,
I want to create a vector x where all n elements are for example c.
I can do this by:
n=5;
x=zeros(1,n);
x(x==0) = 1;
But how to do this in more simple way.
Thanks a lot!

采纳的回答

Walter Roberson
Walter Roberson 2011-10-7
repmat(c,1,n)
or
c * ones(1,n)
or
c + zeros(1,n)
or
c(ones(1,n)) %yes, even with scalar c

更多回答(1 个)

bym
bym 2011-10-6

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by