How can I create the following vector??

1 回表示 (過去 30 日間)
OSCAR ZAMORA PICAZO
OSCAR ZAMORA PICAZO 2016 年 5 月 19 日
コメント済み: Guillaume 2016 年 5 月 19 日
I have a vector called "y", which is for plotting values in the y axis. Also, I have a variable which is a scalar number, but I want to create a vector with the number of places of "y", but having all values of this vector the same value of that variable.
As an example: y = 0:0.5:3;
r = 30
r' = [30 30 30 30 30 30]
The thing is that my vector "y" is much longer than that.
So, how can I create the vector called "r'"?

回答 (1 件)

Adam
Adam 2016 年 5 月 19 日
編集済み: Adam 2016 年 5 月 19 日
r = repmat( 30, [numel(y), 1] );
or
r = 30 * ones( numel(y), 1 );
or
r = 30 + zeros( numel(y), 1 ) );
I haven't tested which is more efficient.
  1 件のコメント
Guillaume
Guillaume 2016 年 5 月 19 日
or
r = repelem(30, numel(y));
in R2015a or later

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

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by