Add 3 to just the odd-index elements

93 ビュー (過去 30 日間)
Edward Prentice
Edward Prentice 2013 年 10 月 11 日
コメント済み: Walter Roberson 2025 年 2 月 4 日 5:31
And have a question regarding 2. Let x = [2 5 1 6]. b. Add 3 to just the odd-index elements
They give the answer as
b = x(1:2:end) + 3
but that makes a new matrix with just two numbers in it.
Like so: "b =
21 20
"
Is the question or the answer wrong?
  2 件のコメント
Harshal
Harshal 2025 年 2 月 4 日 4:25
ADD 16 TO EACH ELEMENTS OF X
Walter Roberson
Walter Roberson 2025 年 2 月 4 日 5:31
for O = 1 : numel(X); X(O) = X(O) + sum(primes(9)) - 1; end

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

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 10 月 11 日
編集済み: Azzi Abdelmalek 2013 年 10 月 11 日
x = [2 5 1 6]
x(1:2:end)= x(1:2:end) + 3
  1 件のコメント
Edward Prentice
Edward Prentice 2013 年 10 月 15 日
Many thanks.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by