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

2 ビュー (過去 30 日間)
Steve
Steve 2011 年 10 月 6 日
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 月 7 日
+1 for the last one. The force is strong in you

サインインしてコメントする。

その他の回答 (1 件)

bym
bym 2011 年 10 月 6 日
x = ones(1,5)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by