Add 3 to just the odd-index elements

94 Ansichten (letzte 30 Tage)
Edward Prentice
Edward Prentice am 11 Okt. 2013
Kommentiert: Walter Roberson am 4 Feb. 2025 um 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 Kommentare
Harshal
Harshal am 4 Feb. 2025 um 4:25
ADD 16 TO EACH ELEMENTS OF X
Walter Roberson
Walter Roberson am 4 Feb. 2025 um 5:31
for O = 1 : numel(X); X(O) = X(O) + sum(primes(9)) - 1; end

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 11 Okt. 2013
Bearbeitet: Azzi Abdelmalek am 11 Okt. 2013
x = [2 5 1 6]
x(1:2:end)= x(1:2:end) + 3

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by