フィルターのクリア

really need help on this question!!!! I want to calculate the sum of all odd number, where do I do wrong?

1 回表示 (過去 30 日間)
clear all, close all, clc, format compact, format long g
A=[12 2 33 15 66;
40 54 79 14 14;
88 2 54 30 47;
37 85 92 14 48;
55 19 88 62 37;
33 12 23 17 25;
75 59 40 26 24;
9 20 44 85 88;
45 57 36 25 49;
92 62 46 88 58];
answer=0;
for m=1:length(A);
for n=1:length(A);
if rem(A(m,n),1)==0
answer=answer+A(m,n);
end
end
end
answer
  3 件のコメント
kanghao he
kanghao he 2016 年 11 月 22 日
I have tried what you are saying. Really appreciated. Unfortunately, the correct value should be 909 instead of 2225.
James Tursa
James Tursa 2016 年 11 月 22 日
Change your test from
if rem(A(m,n),1)==0
to
if rem(A(m,n),2)==1

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

採用された回答

Andrei Bobrov
Andrei Bobrov 2016 年 11 月 19 日
編集済み: Andrei Bobrov 2016 年 11 月 19 日
A=[12 2 33 15 66;
40 54 79 14 14;
88 2 54 30 47;
37 85 92 14 48;
55 19 88 62 37;
33 12 23 17 25;
75 59 40 26 24;
9 20 44 85 88;
45 57 36 25 49;
92 62 46 88 58];
out = sum(A(rem(A,2)~=0));

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by