Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
Steve
Steve am 6 Okt. 2011
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!

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

bym
bym am 6 Okt. 2011
x = ones(1,5)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by