Add 3 to just the odd-index elements

89 vues (au cours des 30 derniers jours)
Edward Prentice
Edward Prentice le 11 Oct 2013
Commenté : Walter Roberson le 4 Fév 2025 à 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 commentaires
Harshal
Harshal le 4 Fév 2025 à 4:25
ADD 16 TO EACH ELEMENTS OF X
Walter Roberson
Walter Roberson le 4 Fév 2025 à 5:31
for O = 1 : numel(X); X(O) = X(O) + sum(primes(9)) - 1; end

Connectez-vous pour commenter.

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 11 Oct 2013
Modifié(e) : Azzi Abdelmalek le 11 Oct 2013
x = [2 5 1 6]
x(1:2:end)= x(1:2:end) + 3

Plus de réponses (0)

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by