Question

5) Write Matlab expressions to extract only the elements at odd positions in a vector (i.e....

5) Write Matlab expressions to extract only the elements at odd positions in a vector (i.e. the 1st, 3rd, 5th, 7th…, elements of the vector), regardless of the length of the vector. Make sure your expression can work on vectors with odd or even number of elements.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Lets say the vector name is vec

Then Matlab expressions to extract only the elements at odd positions in a vector is

vec(1:2:length(vec))

Example:
---------
vec = [1,2,3,4,5,6,7]
Then 
vec(1:2:length(vec)) gives
ans =
   1   3   5   7

vec = [1,2,3,4,5,6,7,8]
Then
vec(1:2:length(vec)) gives
ans =
   1   3   5   7

vec(1:2:length(vec))

Add a comment
Know the answer?
Add Answer to:
5) Write Matlab expressions to extract only the elements at odd positions in a vector (i.e....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT