Problem 6. Select every other element of a vector
Solution Stats
Problem Comments

33 Comments
Not clear.
What does it mean? It is not clear
It's not understandable.
This problem is definitely not clear.
Select the first, the third, the fifth, the seventh, ... element.
nice problem
I cant understand this problem.
nice
All solutions with score 10 or 11 use the regexp cheat.
very good one
Yes, you should change the redaction of the problem,maybe
function y = everyOther(x)
for i=1:length(x)
if mod(x(i),2)~=0
y(i)=x(i)
end
end
y=y(y>0)
end
What's wrong with this solution?
y = x(mod(x,2)==1);
it's not working, and i cant see why
nice problem
nice
good
I can't understand, why is this wrong?
j=1;
for i=1:length(x)
if rem(x(i),2)~=0
y(j)=x(i);
j=j+1;
end
end
Nice problem, but I have been doing this with my son and it would be good if the exercises were more gently graduated with relevant syntax so he can learn without relying on his dad knowing Matlab!
I can't believe someone solved this with size 9.
The leading solution is not a solution. It just makes all the test assertions true.
Indexing is one of more important things in matlab and matrices. Gotta learn them good before heading on.
Helo, hey hey ey
Indexing is one of more important things in matlab and matrices. Gotta learn them good before heading on.
Test suite suggests solution !
nice
the example made confusion
cool!
nice!
cool!
hard
I overcomplicated this one at first, but once you figure it out, it's not too bad
Absolutely mind boggling
this one's pretty good
Solution Comments

1 Comment
how easy amk

1 Comment
Eazy Peazy
what is the value of life?

1 Comment
yes

2 Comments
Not too bad, tests vector manipulation
good job

1 Comment
not bad

1 Comment
Not too complicated

1 Comment
This problem helped me recall how to code with matrices and manipulate elements of a matrix.

1 Comment
nice

1 Comment
This is so simple, yet so compled.

3 Comments
Very simple but really nice! It shows in an elementary way the very core of MATLAB language philosophy.
nice!
GOOD

1 Comment
It 'd be better to distinguish the index ot vector and the value of vector.

2 Comments
challenging!
Yup !! Good one !

1 Comment
Answer in Test Suite. Lol.

1 Comment
hah, correct answer in the tests.

2 Comments
cool!
nice!

1 Comment
this question is ambiguity...

1 Comment
LOL, the solution is in the Test Suite :)

1 Comment
why wrong?
My program woks!

1 Comment
error in template

1 Comment
easy

1 Comment
this was so easy

1 Comment
why is it we cant just see a correct answer once we've submitted enough wrong answers? That would actually improve learning time as opposed to going round in circles not knowing what to do.

1 Comment
Nice one!

1 Comment
Nice XU

1 Comment
Great to solve

1 Comment
Great to solve

1 Comment
How to view the leasing solution?

2 Comments
Nice and Easy
de dang va hay

1 Comment
Why doesn't this work??

1 Comment
nice!

2 Comments
what is this code means?
This same exact code has been posted for numerous problems and is not a true solution. It appears to be a way of hacking the Test Suite into accepting the code as a correct solution. It is also concise, so it always appears to be the "leading" solution. (I have only checked a handful of "leading solutions", so this is a conjecture on my part.)

1 Comment
The solution is given in the test suite!

1 Comment
works with numel(x) OR length(x)

1 Comment
Great!,A pretty useful problem to solve!

4 Comments
Good job!
keep up
nice
Nice!

2 Comments
very easy
please provide me the solution

2 Comments
good
nice

2 Comments
HAHAHAHA
nice

1 Comment
This solution is wrong. even if it is considered correct. This solution would eliminate elements with value equal to 0 as well.

2 Comments
I wrote:
function y = everyOther(x)
n=0;
for i=1:length(x)
if rem (i,2)==0
n=n+1
y(in)= x(i1);
end
end
end
Could someone explain why it failed?
nice

1 Comment
nice

3 Comments
y = x(mod(x,2)==1);
why is it not working? it works in matlab
nice
I did the same thing...

2 Comments
Coding in my matlab2014 before submit is a good thicks.
nice

2 Comments
Still confused why my 'find' solution doesn't work
nice

2 Comments
Great i liked this
nice

2 Comments
try to minimize the size
nice

2 Comments
Is this unfair?
nice

2 Comments
vector concept is different with array.
nice

2 Comments
done
nice

2 Comments
nice
good

1 Comment
This problem is not clear to understand, you must return all the odd indexs.

1 Comment
amazing problem

1 Comment
':' is superfluous but does mean it will work on matrices, not just vectors.
Problem Recent Solvers28205
Suggested Problems

1834 Solvers

Sum all integers from 1 to 2^n
12497 Solvers

459 Solvers

411 Solvers

396 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!