I am trying to create a matlab variable that correlates with a vector.

1 view (last 30 days)
The given vector in my problem is v34= [1:100}. I have to create a MATLAB variable v1 that adds 9 to each one of its 100 elements and a MATLAB variable v2 that adds 3 to each of its odd elements. I have tried using start values and nElements but i keep on getting an error. Am i supposed to use nElements for this kind of problem?
  1 Comment
Sagar Damle
Sagar Damle on 23 Feb 2014
Does 'odd elements' mean 'elements with odd index'?
e.g. v34(1),v34(3),v34(43) etc. are the odd elements which you want?

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 23 Feb 2014
Edited: John D'Errico on 23 Feb 2014
What does 1:2:end do for you (inside the parens)? Thus
v34(1:2:end)
Think about how you might use this idea, adding 3 to the elements of interest.
As for adding 9, surely you can add 9 to the entire vector in a trivial way. TRY IT!
If you don't try things and see what happens, you won't learn.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!