Using a loop to make a function

3 ビュー (過去 30 日間)
Gina Barlage
Gina Barlage 2015 年 5 月 29 日
コメント済み: Gina Barlage 2015 年 5 月 29 日
This is the assignment that I was given:
The script should assume vec_in is specified at the command line. The
script should multiply the values at the odd locations of vec_in and
subtract the sum of values at the even location of vec_in. For example, given
>> vec_in = [1 2 3 4 5]; script23;
vec_value =
9 % This is the result of the calculation 1*3*5 – (2+4).
The phrases product and sum are not allowed to be used.
So far this is what I have come up with:
vec_in = [1 2 3 4 5]
for ii = vec_in(1:2:length(vec_in))
vec_out_time =
end
for jj = vec_in (2:2:length(vec_in))
vec_out_add =
end
vec_out = vec_out_time - vec_out_add
Any hints for how I can get around not using sum or product?

回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 5 月 29 日
A = A + B
C = C * D
  1 件のコメント
Gina Barlage
Gina Barlage 2015 年 5 月 29 日
Thanks this helped a lot!

サインインしてコメントする。

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by