Write a function which returns every other element of the vector passed in. That is, it returns the all odd-numbered elements, starting with the first.
Examples:
Input x = [1 3 2 4 3 5] Output y is [1 2 3]
Input x = [5 9 3 2 2 0 -1] Output y is [5 3 2 -1]
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
I don't see why "x(1):2:length(x)" doesn't work, but "x(1:2:length(x))" does if it's the same thing?
It worked for me in MATLAB
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
y = x(1:2:length(x));?
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
Great to solve
How to view the leasing solution?
Nice and Easy
de dang va hay
Why doesn't this work??
nice!
?
The solution is given in the test suite!
works with numel(x) OR length(x)
Great!,A pretty useful problem to solve!
Good job!
keep up
nice
Nice!
very easy
please provide me the solution
good
nice
HAHAHAHA
nice
This solution is wrong. even if it is considered correct. This solution would eliminate elements with value equal to 0 as well.
I wrote:
function y = everyOther(x)
n=0;
for i=1:length(x)
if rem (i,2)==0
n=n+1
y(i-n)= x(i-1);
end
end
end
Could someone explain why it failed?
nice
You can improve it by doing: y = x(1:2:length(x));
nice
y = x(mod(x,2)==1);
why is it not working? it works in matlab
nice
Coding in my matlab2014 before submit is a good thicks.
nice
Still confused why my 'find' solution doesn't work
nice
Great i liked this
nice
Nice Job
nice
try to minimize the size
nice
Is this unfair?
nice
vector concept is different with array.
nice
done
nice
nice
good
This problem is not clear to understand, you must return all the odd indexs.
if you want concise code,use
y = x(1:2:ceil(end/2)*2-1)
amazing problem
':' is superfluous but does mean it will work on matrices, not just vectors.
1905 Solvers
Side of an equilateral triangle
1465 Solvers
Is this triangle right-angled?
1312 Solvers
314 Solvers
224 Solvers