Add 3 to just the odd-index elements

44 Ansichten (letzte 30 Tage)
Edward Prentice
Edward Prentice am 11 Okt. 2013
Beantwortet: Hunter simmons am 20 Jan. 2022
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?

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 (1)

Hunter simmons
Hunter simmons am 20 Jan. 2022
how to make a vector z that consists of odd-indexed entries of y (y=[100:1])?

Community Treasure Hunt

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

Start Hunting!

Translated by