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 CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by