Clear Filters
Clear Filters

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

1 view (last 30 days)
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!

Accepted Answer

Walter Roberson
Walter Roberson on 7 Oct 2011
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 Comment
bym
bym on 7 Oct 2011
+1 for the last one. The force is strong in you

Sign in to comment.

More Answers (1)

bym
bym on 6 Oct 2011
x = ones(1,5)

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!