How to recursively add odd index elements in a vector

2 ビュー (過去 30 日間)
Noah Swiston
Noah Swiston 2015 年 4 月 28 日
回答済み: Star Strider 2015 年 4 月 28 日
I have an assignment to write a recursive function to add the odd elements within a vector. For example i have a vector
v = 2 4 7 8 10 34 1
I would like to add 2 + 7 + 10 + 1 = 20 using a recursive method. Any help is greatly appreciated!

回答 (1 件)

Star Strider
Star Strider 2015 年 4 月 28 日
You have been asked to add the elements with odd indices. This is different (and easier) than odd elements.
Since this is a homework assignment, I will refer you to the documentation for the colon operator. (No worries — it has absolutely nothing to do the the gastrointestinal tract!)

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by