Add 3 to just the odd-index elements
30 views (last 30 days)
Show older comments
Edward Prentice
on 11 Oct 2013
Commented: Walter Roberson
on 4 Feb 2025
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 Comments
Walter Roberson
on 4 Feb 2025
for O = 1 : numel(X); X(O) = X(O) + sum(primes(9)) - 1; end
Accepted Answer
Azzi Abdelmalek
on 11 Oct 2013
Edited: Azzi Abdelmalek
on 11 Oct 2013
x = [2 5 1 6]
x(1:2:end)= x(1:2:end) + 3
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!