Multiply values in array by *-1

6 ビュー (過去 30 日間)
Edward Keavney
Edward Keavney 2022 年 7 月 28 日
コメント済み: Edward Keavney 2022 年 7 月 28 日
Hi,
I have an array 1X106. I want to be able to multiply specific entries in the array by -1.
e.g., multiplying the 16, 17 and 18 value in the array by -1 whilst still keeping the remainder of the array with the original values.
Any help would be greatly appreciated,
Thanks!

採用された回答

Chunru
Chunru 2022 年 7 月 28 日
a = randn(1, 106);
a(14:20)
ans = 1×7
0.8401 1.6024 1.0470 -1.1157 0.2066 -2.0192 -0.6220
a(16:18)=-a(16:18);
a(14:20)
ans = 1×7
0.8401 1.6024 -1.0470 1.1157 -0.2066 -2.0192 -0.6220
  1 件のコメント
Edward Keavney
Edward Keavney 2022 年 7 月 28 日
Perfect, thank you very much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by