Add 3 to just the odd-index elements

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 comentarios

Harshal
Harshal el 4 de Feb. de 2025
ADD 16 TO EACH ELEMENTS OF X
for O = 1 : numel(X); X(O) = X(O) + sum(primes(9)) - 1; end

Iniciar sesión para comentar.

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 11 de Oct. de 2013
Editada: Azzi Abdelmalek el 11 de Oct. de 2013
x = [2 5 1 6]
x(1:2:end)= x(1:2:end) + 3

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 11 de Oct. de 2013

Comentada:

el 4 de Feb. de 2025

Community Treasure Hunt

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

Start Hunting!

Translated by