A vector is given v=[6, 3, -9, 10, 5, 0, -8, 11, -15]. write a matlab command the doubles the elements that are odd and raises the elements that are even to th power of 2
1 visualizzazione (ultimi 30 giorni)
Image Analyst il 25 Feb 2015
If you want to avoid a loop and do it vectorized, try this:
evenIndexes = 2 : 2 : length(v);
oddIndexes = 1 : 2 length(v);
v(evenIndexes) = v(evenIndexes)........you finish it..
v(oddIndexes) = v(oddIndexes)........you finish it..
You already did the formulas in your code so it should be easy to put them in the code above.
Greig il 25 Feb 2015
Your loop structure above seems a little odd and has some missing "end"s. Try this for a basic loop structure...
if % something
% do something
% do something else
And check out
That should be enough to fix up your code