フィルターのクリア

1x100 vector of all -1

68 ビュー (過去 30 日間)
Zelda Luxenburry
Zelda Luxenburry 2012 年 3 月 15 日
コメント済み: Tushar Chauhaan 2021 年 1 月 15 日
I can't find how to create a vector with dimensions 1x100 where all the values should be -1... i know you can use "zeroes" and "ones" but how do I do this for -1? I also need to make one for the value 2.00049. Thanks!
  1 件のコメント
Tushar Chauhaan
Tushar Chauhaan 2021 年 1 月 15 日
ok

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

回答 (3 件)

Jan
Jan 2012 年 3 月 15 日
x = -ones(1, 100); % Faster than -1*ones(1, 100);
Inside repmat this happens:
a = -1;
x = a(ones(1, 100));
If x does not exist before or is not larger than the wanted result, this works also:
x(1:100) = -1;
But I recommend not to use this, because it depends on the history:
x = rand(11, 11);
...
x(1:100) = -1 % Still a [11 x 11] matrix!

Wayne King
Wayne King 2012 年 3 月 15 日
x = -1*ones(1,100);
y = 2.00049*ones(1,100);

Walter Roberson
Walter Roberson 2012 年 3 月 15 日
Alternative:
x = repmat(-1, 1, 100);
y = repmat(2.00049, 1, 100);

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by